Skip to content

Memory Analysis

Michael Wang edited this page Nov 30, 2022 · 1 revision

The -memfail flag

Adds a runtime check to ensure calls to malloc succeed, and handle them "safely" if not. In essence, if a memory allocation attempt fails (malloc returns NULL), then the requested size will be printed, and if -stacktrace is used, the stack trace of the location will be reported as well.

Memory Analysis Level 1 (-meman1)

This will add a lightweight leak sanitizer to the emitted output. It tracks statistics related to allocation count - the amount of "memory blocks" active on the heap that were requested only by North Hollywood Python's built-in features (invocations of the new keyword, etc..), not external c calls to malloc.

The reported statistics are:

  • Peak allocation count
  • Current allocation count These statistics may be used to detect memory leaks, by comparing the current allocation count before an operation is performed, and after it is performed.

Memory Analysis Level 2 (-meman2)

This does everything in level 1, but in addition, tracks the magnitude of memory allocations (level 1 only tracked the count).

Additionally reported statistics include:

  • Peak allocation size
  • Current allocation size Use the mem::leaksan function found in mem.nhp to sanitize leaks from a certain function (must return None).

Clone this wiki locally