No, in GC a retain/release/autorelease always translates to a no-op.
An "id" or "SomeObject*" translates to a strong reference unless
specifically marked as weak.

So in the GC world, there is no difference between @property(retain) and @property(assign), is there?

"If the object is in the garbage collected zone, the last CFRelease()
does not immediately free the object, it simply makes it eligible to
be reclaimed by the collector when it is discovered to be
unreachableā€”that is,

That's why I got confused.


Well, I think, I have solved the two issues -- at least for my minimal example.
Thanks to all your input, which kept me exploring!


Now, I would like to ask for your advice whether my solutions are OK, and if so, why.

Issue #1:
The memory leak wasn't really a "leak" -- it was just the GC taking its time. In fact, it seemed to start collecting only when my process exceeded 500MB. That seemed to cause a little, but noticeable, judder, so I have now written my CALayer creation code like this:

   ... create CGImageRef cgImage
   CALayer* imgLayer = [CALayer layer];
   imgLayer.contents = (id) cgImage;
   CGImageRelease( cgImage );
   if ( [NSGarbageCollector defaultCollector] )
      [[NSGarbageCollector defaultCollector] collectExhaustively];

Is there a more elegant way to achieve that?


Issue #2:
It seems to me that, for some reason, the delegate that I create for the second layer to do drawLayer:inContext:
got GC'ed .

My original code was

TextLayerDelegate * textlayer_delegate = [[TextLayerDelegate alloc] init];
    textLayer_ = [CALayer layer];
    textLayer_.delegate = textlayer_delegate;
    [mainLayer_ addSublayer: textLayer_ ];

(Note that the above code works fine in the non-GC world!)

Now, I inserted CFRetain() like so:

TextLayerDelegate * textlayer_delegate = [[TextLayerDelegate alloc] init];
    CFRetain( textlayer_delegate );

And it seems to work now, even in the GC world!
(The textLayer_ is instantiated only once during the lifetime of the app.)

The big question now is: do I have to CFRetain() the delegate here, because of what the "GC programming guide" says in section "Delegate references" of delegates? Or is there some other reason? Or is it mere chance that it works?

I am asking, because this case might occur several times in my real app (the screensaver).


Best regards,
Gabriel.

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to