Objective-C Bridge Memory Management

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Objective-C Bridge Memory Management

Sean P. DeNigris
Administrator
How does Obj-C garbage collection map to Squeak?

For example:
* When an Obj-C object is garbage collected in Squeak, is the release propagated back to Obj-C (does it even have to be)?
* Is it safe to autorelease objects? What is the "event loop" of obj-c code called from Squeak?
* If objects become zombies, how long do they hang around? Are they finally destroyed when I quit the image?

Thanks.
Sean
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Objective-C Bridge Memory Management

johnmci
Mmm the water is really deep in this pool.

This is no mapping.

Objective-C objects which get GCed get dealloc messages, there is no
way to feed that back to Squeak.

When a Smalltalk object gets GCed you should setup a weak relationship
so that on the finalization action you could then send release to the
companion Objective-C object.
I never did this as it is tricky, difficult and nasty when it goes
wrong. Still you might be lucky when you implement it, you'll find
working examples in the image.

Look for use of the autorelease pool in the objective-c bridge.

The event loop runs each time you call the get next primitive, so
making an auto-released object without a pool would cause the object
to be released at an undetermined time.

Zombies are of course released when a unix process, aka os-x
application, ios app terminates. All resources are returned for reuse
by other users.

As an exercise think about the asUTF8String and what happens, welcome
to managed memory allocation.
Oh yes a finalization solution work work fine for this case.


On Sun, May 1, 2011 at 10:38 PM, Sean P. DeNigris <[hidden email]> wrote:

> How does Obj-C garbage collection map to Squeak?
>
> For example:
> * When an Obj-C object is garbage collected in Squeak, is the release
> propagated back to Obj-C (does it even have to be)?
> * Is it safe to autorelease objects? What is the "event loop" of obj-c code
> called from Squeak?
> * If objects become zombies, how long do they hang around? Are they finally
> destroyed when I quit the image?
>
> Thanks.
> Sean--
> View this message in context: http://forum.world.st/Objective-C-Bridge-Memory-Management-tp3489203p3489203.html
> Sent from the Smalltalk VM - Beginners mailing list archive at Nabble.com.
> _______________________________________________
> VM-beginners mailing list
> [hidden email]
> http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners
>



--
===========================================================================
John M. McIntosh <[hidden email]>
Corporate Smalltalk Consulting Ltd.  http://www.smalltalkconsulting.com
===========================================================================
_______________________________________________
VM-beginners mailing list
[hidden email]
http://lists.squeakfoundation.org/mailman/listinfo/vm-beginners