NSView resource leak when using TCustomControl
Original Reporter info from Mantis: zpeterson @boramis
-
Reporter name: Zoë Peterson
Original Reporter info from Mantis: zpeterson @boramis
- Reporter name: Zoë Peterson
Description:
Controls embedded in a TCocoaManualScrollView (TCustomControl) currently leak their NSView handles.
EmbedInManualScrollView is used in two places, TCocoaWSCustomControl.CreateHandle and TCocoaWSCustomSplitter.CreateHandle. Both allocate the base control, call EmbedInManualScrollView, and return the scroll view as the result. At that point, the inner view has a retainCount of 2, one from the alloc.init and one from the scrollview's subview reference. Neither TCocoaWSCustomControl nor TCocoaWSCustomSplitter have DestroyHandle implementations, so the default one runs, which only releases the "Handle" property. The manual scroll view is released and deallocated, but the embedded one still has the outstanding reference. You can verify that by adding logging to the places where TCocoaCustomControl are allocated and in its dealloc; there will be many more alloc calls than dealloc ones.
EmbedInScrollView has an optional parameter (defaults to true) that releases the embedded view after the scroll view is created and the subview is assigned. That keeps the resulting retain count at 1.
This patch adds the same release behavior to EmbedInManualScrollView, though since there isn't anywhere that doesn't want that behavior, I left out making it optional.
As an alternative, TCocoaManaualScrollView could call the release when it's deallocated, or the relevant controls could do it in DestroyHandle. TCocoaSpinEdit does similar embedding and manages the reference counts explicitly in lclReleaseSubcontrols.
Mantis conversion info:
- Mantis ID: 35944
- Version: 2.0.3 (SVN)
- Fixed in revision: 61688 (#0ff8e75f)