| Ticket UUID: | 57844100da9bb7b85382c92c7b68d9820b6807e8 | |||
| Title: | Aqua: fix leak in TkScrollWindow() | |||
| Type: | Patch | Version: | 8.6.13 | |
| Submitter: | chrstphrchvz | Created on: | 2023-06-05 04:15:49 | |
| Subsystem: | 18. [text] | Assigned To: | fvogel | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Closed | Last Modified: | 2023-06-11 08:38:45 | |
| Resolution: | Fixed | Closed By: | fvogel | |
| Closed on: | 2023-06-11 08:38:45 | |||
| Description: |
See attached patch. This leak occurs every time a text widget is scrolled. It has been present presumably since [0d901f09cdbf]: a comment had been added about mutable shapes needing to be released, but immutable shapes need to be released too. I do not know what may have given the impression that immutable shapes did not also need to be released; despite the sparse HIShape API documentation, “Create” being in the name of the function HIShapeCreateWithRect() indicates ownership is passed to the caller (see https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFMemoryMgmt/Concepts/Ownership.html#//apple_ref/doc/uid/20001148-CJBEJBHH). Excerpt of leaks command output: STACK OF 275 INSTANCES OF 'ROOT LEAK: <HIShape>': 11 dyld 0x7ff80c68541f start + 1903 10 wish8.7 0x10bd5dde9 main + 201 tkAppInit.c:97 9 libtcl9tk8.7.dylib 0x10cd9aef5 Tk_MainEx + 10005 tkMain.c:389 8 libtcl9tk8.7.dylib 0x10cd102b8 Tk_MainLoop + 152 tkEvent.c:2123 7 libtcl9.0.dylib 0x10f7eb34e Tcl_DoOneEvent + 3694 tclNotify.c:1020 6 libtcl9.0.dylib 0x10f8ead6b TclServiceIdle + 1595 tclTimer.c:752 5 libtcl9tk8.7.dylib 0x10d24f73a DisplayText + 12490 tkTextDisp.c:4373 4 libtcl9tk8.7.dylib 0x10d441dff TkScrollWindow + 2063 tkMacOSXDraw.c:1152 3 com.apple.HIServices 0x7ff81224fdc5 HIShapeCreateWithRect + 16 2 com.apple.HIServices 0x7ff81224fd42 CreateEmptyShape(bool, bool) + 48 1 com.apple.CoreFoundation 0x7ff80ca422b2 _CFRuntimeCreateInstance + 748 0 libsystem_malloc.dylib 0x7ff80c82d149 _malloc_zone_malloc_instrumented_or_legacy + 88 … STACK OF 277 INSTANCES OF 'ROOT LEAK: <HIShape>': 11 dyld 0x7ff80c68541f start + 1903 10 wish8.7 0x10bd5dde9 main + 201 tkAppInit.c:97 9 libtcl9tk8.7.dylib 0x10cd9aef5 Tk_MainEx + 10005 tkMain.c:389 8 libtcl9tk8.7.dylib 0x10cd102b8 Tk_MainLoop + 152 tkEvent.c:2123 7 libtcl9.0.dylib 0x10f7eb34e Tcl_DoOneEvent + 3694 tclNotify.c:1020 6 libtcl9.0.dylib 0x10f8ead6b TclServiceIdle + 1595 tclTimer.c:752 5 libtcl9tk8.7.dylib 0x10d24f73a DisplayText + 12490 tkTextDisp.c:4373 4 libtcl9tk8.7.dylib 0x10d441e0f TkScrollWindow + 2079 tkMacOSXDraw.c:1153 3 com.apple.HIServices 0x7ff81224fdc5 HIShapeCreateWithRect + 16 2 com.apple.HIServices 0x7ff81224fd42 CreateEmptyShape(bool, bool) + 48 1 com.apple.CoreFoundation 0x7ff80ca422b2 _CFRuntimeCreateInstance + 748 0 libsystem_malloc.dylib 0x7ff80c82d149 _malloc_zone_malloc_instrumented_or_legacy + 88 | |||
| User Comments: |
fvogel added on 2023-06-11 08:38:45:
Makes sense to me. Patch now merged in core-8-6-branch and trunk. chrstphrchvz added on 2023-06-10 23:22:10: The HIShape documentation is referring to the optimization where HIShapeCreateCopy() is equivalent to CFRetain() when called with an immutable HIShape. Both immutable and mutable HIShapes are still Core Foundation objects, which by default are manually reference counted on Objective-C using CFRetain() and CFRelease(). fvogel added on 2023-06-08 06:37:19: Extract from one of my discussions with Marc Culler that could (perhaps) shed some light about why one could think immutable shapes would not need to be released: So what Apple says is that immutable shapes are refcounted. I think we deduced that, in contrast, mutable shapes are not refcounted and as such should be released. And also, that immutable shapes being refconuted do not need to be released since they are refcounted. Your excerpts of leaks command output seems to show that deduction was incorrect.The typedefs for HIShapeRef and HiMutableShapeRef are: typedef const struct __HIShape *HIShapeRef; typedef struct __HIShape *HIMutableShapeRef; The header file is .../HIServices.framework/Headers/HIShape.h (depending on whether you have XCode or the command line tools). In the header file Apple says: * One of the biggest benefits of HIShape is that we have mutable * and immutable variants. This means that immutable shapes can be * created and passed around and 'copied' very quickly, since they * are actually refcounted when copied. This avoids needing to do * the handle-to-handle copies that occur right now with * RgnHandle-based APIs. fvogel added on 2023-06-08 06:11:36: Thanks! Patch committed in [b84e2c81a2]. I'm pretty sure I had discussions with Marc Culler about this area of code, let me see whether I can find traces of it in my inbox. It happened near [0d901f09cd] and its next commit [1844495a]. nab added on 2023-06-07 07:48:16: Hi Christopher, I've tested your two lines patch on my customTK and it does not hurt anything. thanks, ++ | |||
Attachments:
- 57844100.diff [download] added by chrstphrchvz on 2023-06-05 04:16:36. [details]
