[Vm-dev] [OpenSmalltalk/opensmalltalk-vm] fix event memory leak (#373)

John M McIntosh johnmci at smalltalkconsulting.com
Thu Feb 28 20:17:59 UTC 2019

No you do not need the RELEASEOBJ

Before ARC there was a lot of work involved in managing memory.
For situation where you allocated or made a copy of an object (various rules).

X = [NSMutableArray alloc] init]);

Then you had to ensure you released the object when you were done via release, or tag it via autorelease

For the case where an object was created but autoreleased you then had to ensure you retain it either via an explicit retain or use of a retain property,

self.retainedObject = [NSArray array]; //returns autorelease object
retainedObject = [[NSArray alloc] init];

had very different meaning as the self. would do the assignment and retain, but use without self. would not do the retain, which was not needed as the alloc/init gives a retain count of 1.

Post ARC the compiler is aware of the scope of the life of the object and inserts retain/release as needbe.

That all said what is going on is very subtle. The actual problem is that the
X = [NSMutableArray alloc] init]);
is handled OK by ARC because the object is autoreleased when the method ends.

However the question is well what happens to the auto release pool?
When does that get cleaned up?

That is the actual problem, and adding the auto-release pool cleans up the NSEvents that are creating the majority of the garbage, since there is no autorelease wrapper for the callout from the interp.c code.

There likely are others, mmm ioSetCursor
Maybe there needs to be a general rule that any call outs to obj logic from interp.c have to have an autorelease pool?

John M. McIntosh. Corporate Smalltalk Consulting Ltd https://www.linkedin.com/in/smalltalk

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Thursday, February 28, 2019 9:59 AM, Tobias Pape <notifications at github.com> wrote:

>> Ok, as @krono pointed out
>> NSMutableArray *alienEventQueue = AUTORELEASEOBJ([[NSMutableArray alloc] init]);
>> with the autoreleasepool.
> Do we need the `RELEASEOBJ` in this case?
>> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, [view it on GitHub](https://github.com/OpenSmalltalk/opensmalltalk-vm/pull/373#issuecomment-468373330), or [mute the thread](https://github.com/notifications/unsubscribe-auth/AhLyW0_DSJBNfTEFzQknE8qU_rqNMnwtks5vSBkBgaJpZM4bWbAu).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/vm-dev/attachments/20190228/bfd5d1d3/attachment.html>

More information about the Vm-dev mailing list