• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Garbage Collection in Objective-C++
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Garbage Collection in Objective-C++


  • Subject: Re: Garbage Collection in Objective-C++
  • From: Chris Hanson <email@hidden>
  • Date: Tue, 5 Feb 2008 20:09:25 -0800

On Feb 5, 2008, at 6:53 PM, David Elliott wrote:

wxObjcAutoRefFromAlloc<void*> s_foo = [[SomeClass alloc] init];

The idea is that wxObjcAutoRefFromAlloc constructs with an already- retained object (e.g. one from alloc) and releases on destruction. Copy construction results in a retain so that's not an issue. Ignore that class for now though as the implementation of it is horrible, so don't go looking it up.


Really, I think the main issue with what you're trying to do is expressed above.

(1) You're assigning an object reference to something that's typed (effectively) as "void *" so you're pretty much hiding the object reference from the collector.

(2) You're using different memory management semantics than normal, by expecting the initial -retain sent to the object reference to come from "outside" the object you're passing it to.

You can change #2 so that the above line of code under non-GC would read like this:

wxObjcAutoRefFromAlloc<void*> s_foo = [[[SomeClass alloc] init] autorelease];

In other words, assigning an object reference *to* one of these should cause a retain.

Then, once your wxObjcAutoRefFromAlloc<T> class retains on assignment, you can convert it from sending -retain and -release to instead call the CFRetain and CFRelease functions. These effectively add and remove a root under GC, and they will cause -retain and -release to be sent under non-GC, so you should get correct behavior in all circumstances.

  -- Chris

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Garbage Collection in Objective-C++
      • From: David Elliott <email@hidden>
References: 
 >Garbage Collection in Objective-C++ (From: David Elliott <email@hidden>)

  • Prev by Date: Re: Searching for "whole word" in NSString
  • Next by Date: Re: Garbage Collection in Objective-C++
  • Previous by thread: Garbage Collection in Objective-C++
  • Next by thread: Re: Garbage Collection in Objective-C++
  • Index(es):
    • Date
    • Thread