# Memory Profiling

Detect memory leaks and analyze allocation patterns.

## Quick Leak Check

Wrap any code block to detect potential memory leaks.

## Memory Snapshots

Compare memory state before and after operations.

## Allocation Tracking

Track every allocation with detailed statistics.

## Full Memory Report

## CI Integration

Automatically check for leaks in CI with Valgrind.

## Profiling Features

Feature | Module | Description
--- | --- | ---
Allocation Tracking | allocation.rs | Track every alloc/dealloc with stats
Memory Snapshots | snapshot.rs | Capture and diff memory state
Leak Detection | leak_detector.rs | Identify potential memory leaks
Heap Profiling | heap.rs | System-level heap analysis
Size Histogram | allocation.rs | Distribution of allocation sizes

## Enable Profiling

Add the `profiling` feature flag:

    prax-query = {{ version = "0.3", features = ["profiling"] }}

## CI Workflows

### Leak Detection Tests

Run profiling module tests on every PR

### Valgrind Analysis

Check for definite memory leaks (Linux)

### AddressSanitizer

Runtime memory error detection (nightly)

### DHAT Profiling

Heap allocation analysis

## Benchmarks

Run memory profiling benchmarks:

    cargo bench --package prax-query --bench memory_profile_bench