Description:
I'm creating this issue to document a known cause of false-positive memory leaks in DUnitX when testing code that utilizes resourcestring.
The Issue:
DUnitX reports a memory leak for any test method that triggers the first use of a specific resourcestring.
Root Cause:
The Delphi RTL function System.LoadResString(ResStringRec: PResStringRec): string maintains an internal global cache of loaded resource strings.
- When a
resourcestring is accessed for the first time (e.g., via Exception.CreateRes or direct usage), the RTL loads it from the resource section and adds it to this global cache.
- This allocation persists for the lifetime of the application.
- Since DUnitX calculates leaks by comparing memory usage before and after a test method, this one-time cache allocation is flagged as a leak for that specific test.
Reproduction:
Any test that causes a unique resourcestring to be loaded will trigger this.
- Example: Calling
raise EOsslError.CreateRes(@resSomeError) inside a test.
Workaround / Solution:
To avoid these false positives, you must ensure the resource strings are cached before the test execution phase begins.
- Action: Pre-load all relevant resource strings in the
[SetupFixture] method of your test unit.
- Alternative: Mark specific tests with
[IgnoreMemoryLeaks], though this may hide real leaks.
Description:
I'm creating this issue to document a known cause of false-positive memory leaks in DUnitX when testing code that utilizes
resourcestring.The Issue:
DUnitX reports a memory leak for any test method that triggers the first use of a specific
resourcestring.Root Cause:
The Delphi RTL function
System.LoadResString(ResStringRec: PResStringRec): stringmaintains an internal global cache of loaded resource strings.resourcestringis accessed for the first time (e.g., viaException.CreateResor direct usage), the RTL loads it from the resource section and adds it to this global cache.Reproduction:
Any test that causes a unique
resourcestringto be loaded will trigger this.raise EOsslError.CreateRes(@resSomeError)inside a test.Workaround / Solution:
To avoid these false positives, you must ensure the resource strings are cached before the test execution phase begins.
[SetupFixture]method of your test unit.[IgnoreMemoryLeaks], though this may hide real leaks.