Objective-C memory management
Alan Snyder
javalists at cbfiddle.com
Tue Jan 7 18:08:41 UTC 2025
I’m a bit confused about how the macOS implementation of JDK uses Objective-C memory management.
Does it use ARC?
I’m guessing it does, because I see dealloc methods that clear pointer variables without first releasing them.
However, if I put an Xcode breakpoint on -[MTLLayer dealloc], the breakpoint is never hit after I close windows or dismiss menus, which suggests the MTLLayer instances are leaked. This matters because MTLLayer instances have associated CVDisplayLinks, which have active threads.
I see that Java_sun_lwawt_macosx_CFRetainedResource_nativeCFRelease is called on MTLLayer instances, but the retain count at that time is 6.
Three other Objective-C instances are released using this function: AWTView, AWTWindow_Panel, and AWTSurfaceLayers, but that is not enough to do the job.
Apple has tools for diagnosing memory leaks, but I don’t know how to run them on a JDK based application.
More information about the core-libs-dev
mailing list