Why does memory leak even when I release the HeapObject object obtained from swift_allocBox?

Hi John, I've been doing some more digging into this. While I haven't been able to find a fix yet, I have some questions.

I was able to get a closer look at what I believe is the closure context for the closure that I'm storing in a box. It was a swift::metadataimpl::SwiftRetainableBox wrapped HeapObject and I confirmed that swift_release is indeed being called on the underlying HeapObject.

However, what I found weird was that the strong ref count of this HeapObject was 1, both before and after the swift_release call. I got a dump for the object before and after the swift_release call -

// Before
HeapObject: 0x100d04450
HeapMetadata Pointer: 0x100004368.
Strong Ref Count: 1.
Unowned Ref Count: 1.
Weak Ref Count: 1.
Uses Native Retain: Not a class. N/A.
RefCount Side Table: 0x0.
Is Deiniting: false.

// After
HeapObject: 0x100d04450
HeapMetadata Pointer: 0x0.
Strong Ref Count: 1.
Unowned Ref Count: 0.
Weak Ref Count: 0.
// Rest didn't print due to seg faulting

Is this expected?

I don’t think we bother writing 0 into the refcount when we see it’s 1.

1 Like

John, I apologize for the false alarm and wasted time!

I was checking the memory leaks using the leaks command line tool and lldb and It seems like both, for some reason ignore my DYLD_LIBRARY_PATH override (which was needed since the autodiff builtins are defined there).

1 Like