• 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
reasonable way of avoiding using autorelase?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

reasonable way of avoiding using autorelase?


  • Subject: reasonable way of avoiding using autorelase?
  • From: Ben Dougall <email@hidden>
  • Date: Fri, 28 Mar 2003 14:30:18 +0000

just learning obj-c/cocoa. on memory management:

this example that's given as an incorrect way of setting up a method to return a reference to an object:

-(NSObject *)eCancer
{
NSObject *result = [[NSObject alloc] init];
return result;
}

i understand what the problem is here. you're initialising and allocating an object (retain count=1), then you're returning it's reference/pointer to another object (retain count will now be 2, if that object retains it as it should if it's going to use it) but only one object needs the new object instance. and autorelease is the way to handle this as it's a temporary way for the above method to retain the object pointed to by result.

alternatively to autoreleasing, would having the object that asks for and recieves this object reference, just not retain it, be a way of doing it? and use the above object's retain for/in the calling object? seems like a simple, possible short cut to me. i get the feeling that using an autorelease is slightly more inefficient than not using an autorelease. also autoreleases are not to be used if multithreading right?

i also get the feeling there must be a problem with this idea, but i'm not sure what, if there is one? is it just a practical problem of whichever object requests and gets the object instance needs to know not to retain it itself, whereas usually it's supposed to?
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: reasonable way of avoiding using autorelase?
      • From: Joe Osborn <email@hidden>
    • Re: reasonable way of avoiding using autorelase?
      • From: Marco Binder <email@hidden>
    • Re: reasonable way of avoiding using autorelase?
      • From: Nicholas Riley <email@hidden>
  • Prev by Date: Creating a string with attachements from thin air... and an image...
  • Next by Date: Re: reasonable way of avoiding using autorelase?
  • Previous by thread: Re: Creating a string with attachements from thin air... and an image...
  • Next by thread: Re: reasonable way of avoiding using autorelase?
  • Index(es):
    • Date
    • Thread