Skip to content

Conversation

gabr42
Copy link
Contributor

@gabr42 gabr42 commented Dec 13, 2016

Implemented two EnableMemoryLeakReporting-mode methods
StartRegisteringAllThreadAllocationsAsExpectedLeaks and
StopRegisteringAllThreadAllocationsAsExpectedLeaks. Windows only.

Rationale: customer calls RegisterPropertyEditor from a program (not
package) and RegisterPropertyEditor creates a memory leak which cannot
be cleaned (local TList in a system unit) and cannot be correctly
registered (Unknown and UnicodeString leaks).

Call StartRegisteringAllThreadAllocationsAsExpectedLeaks to register all
following memory allocations as expected memory leaks.

Call StopRegisteringAllThreadAllocationsAsExpectedLeaks to stop that
behaviour.

Only one thread at a time can be in that state; if a second thread tries
to enter it, it will be blocked until the first thread exits from that
state.

Implemented two EnableMemoryLeakReporting-mode methods
StartRegisteringAllThreadAllocationsAsExpectedLeaks and
StopRegisteringAllThreadAllocationsAsExpectedLeaks. Windows only.

Rationale: customer calls RegisterPropertyEditor from a program (not
package) and RegisterPropertyEditor creates a memory leak which cannot
be cleaned (local TList in a system unit) and cannot be correctly
registered (Unknown and UnicodeString leaks).

Call StartRegisteringAllThreadAllocationsAsExpectedLeaks to register all
following memory allocations as expected memory leaks.

Call StopRegisteringAllThreadAllocationsAsExpectedLeaks to stop that
behaviour.

Only one thread at a time can be in that state; if a second thread tries
to enter it, it will be blocked until the first thread exits from that
state.
@pleriche
Copy link
Owner

Hi Primoz,

Thanks for the contribution. Just two issues I have picked up (please correct me if I am wrong):

  1. It appears that the new Start/StopRegistering... calls are also declared outside of FullDebugMode, but they only have an effect inside FullDebugMode.
  2. While inside this mode should freed memory blocks not automatically be removed from the registered leaks list? I am a bit worried about overflow, since the leaks list is limited to a couple of thousand entries.

Best regards,
Pierre

@gabr42
Copy link
Contributor Author

gabr42 commented Dec 16, 2016 via email

@pleriche
Copy link
Owner

pleriche commented Dec 16, 2016

FullDebugMode is separate from EnableMemoryLeakReporting: Leak reporting works outside of FullDebugMode as well, but you don't get stack traces.

Regarding the logging of all allocations as leaks, I fear that even if you deregister all blocks in FreeMem that the maximum of about 2300 entries under 32-bit (half under 64-bit) in the registered leak list will still not be enough. It really wasn't designed with this purpose in mind. The code that manages it is also not particularly fast (it performs linear searches), and without a redesign it will become slow if you increase the size of the list.

@gabr42
Copy link
Contributor Author

gabr42 commented Dec 16, 2016 via email

@the-Arioch
Copy link

not very related thought...

May there be a registration of memory blocks, allocated in one thread and freed in another ?

I mean, most of the objects are expected to have a thread-local lives. Owner responsibility is not transferred. But some do, and those some require special measures for access synchronization.

Just a widl idea, that maybe there is both a technical feasibility and a possible benefit to check - for most objects except for specially marked - that they did not passed threads boundary in terms of ownership.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants