{"library":"memray","code":"import memray\nimport os\n\ndef allocate_some_memory():\n    return [0] * 1024 * 1024 # Allocate 8MB\n\nif __name__ == \"__main__\":\n    output_file = \"memray_output.bin\"\n    with memray.Tracker(output_file):\n        my_data = allocate_some_memory()\n    print(f\"Memory profile saved to {output_file}\")\n    # To generate a flame graph, run from your shell:\n    # memray flamegraph memray_output.bin\n    # To programmatically create a report:\n    # from memray import Metadata, MemrayFile\n    # with MemrayFile(output_file) as f:\n    #    metadata = Metadata.parse_file(f)\n    #    print(f\"Total allocations: {len(f.iter_records())}\")","lang":"python","description":"This quickstart demonstrates how to programmatically use `memray.Tracker` to profile a section of code and save the allocation data to a binary file. The output file can then be analyzed using `memray`'s CLI tools (e.g., `memray flamegraph`) or processed programmatically.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}