主要内容

Memory leaks (-sanitizer-selection memleak)

R2026b

Enable detection of memory leaks at runtime

Since R2026b

Description

Specify whether the sanitizer detects memory leaks at runtime. A memory leak occurs when memory is allocated but never freed, leading to increasing memory consumption over time.

Set Option

Set the option using one of these methods:

  • Polyspace Platform user interface (desktop products only): In your project configuration, on the Testing and Profiling tab, select the Sanitizer node, select Select by category, and then select or clear this option.

  • Command line: Use the option -sanitizer-selection and include memleak in the comma-separated list. See Command-Line Information.

  • Python® API: Set the MemoryLeak property in the testing and profiling configuration. See polyspace.project.TestConfiguration.

  • TOML configuration file (.toml.pscfg) — Use the key MemoryLeak in the [SanitizerOptions] table. For example:

    [SanitizerOptions]
    MemoryLeak = true

Why Use This Option

Use this option to detect memory that is allocated but never freed during test execution. Memory leaks can cause your application to consume increasing amounts of memory over time, eventually leading to resource exhaustion.

Settings

On

The sanitizer detects memory leaks at runtime.

Off (default)

The sanitizer does not detect memory leaks.

Dependencies

This option is available only when you select Select by category as the sanitizer selection mode.

Command-Line Information

The command-line workflow for setting this option depends on your workflow.

  • If you build your source and tests using a Polyspace Platform Project — Once you set this option in the project using the Polyspace Platform user interface, you cannot override or modify this option using the polyspace-test command.

  • If you build your sources and xUnit tests using your own toolchain — Specify this option to the polyspace-code-profiler command.

Parameter: -sanitizer-selection
Value: Include memleak in comma-separated list of error categories
Default: off
Example: polyspace-code-profiler -instrument -instrum-dir instrumFolder -sanitizer -sanitizer-selection numeric,memory,memleak -- compileCommand

Version History

Introduced in R2026b