• 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: Newbie: Object life within a method scope
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie: Object life within a method scope


  • Subject: Re: Newbie: Object life within a method scope
  • From: Jiva DeVoe <email@hidden>
  • Date: Tue, 22 Feb 2005 21:24:02 -0700

I think the important thing to understand here is that objects received back from other methods should be assumed to be "autoreleased".

What this means is that they still have a retain count > 0, but they are marked to be released later in the autorelease loop. Here's the thing though, the autorelease loop runs as part of the internal application event loop, which you will not hit until you exit your current method (unless you have something like another thread running which might cause the loop to run).


On Feb 22, 2005, at 2:59 PM, Joseph Feld wrote:

Hi all,

Trying to get a handle on the whole retain and release system (my day job is
in the Java world and the GC has definitely spoiled me) and I'm curious
about the life of an object within a method scope. I found the Memory
Management: Object Ownership and Disposal document on the Apple Dev site and
it states: "A received object is normally guaranteed to remain valid within
the method it was received in (exceptions include multithreaded applications
and some Distributed Objects situations). That method may also safely return
the object to its invoker," which would seem to answer my question.
However, two bullet points later it warns: "Use retain and autorelease when
needed to prevent an object from being invalidated as a normal side-effect
of a message," which has me a bit confused about what normal side-effects of
a message might cause me to lose my object.


So I guess my question is, if I'm not interested in an object beyond the
scope of the method receiving it is it still prudent to retain it to ensure
it survives the scope, or is that unnecessary?


Thanks,
Joe


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


--
Jiva DeVoe
http://www.devoesquared.com
PowerCard - Intuitive Project Management Software for Mac OS X

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Newbie: Object life within a method scope
      • From: Kevin Viggers <email@hidden>
References: 
 >Newbie: Object life within a method scope (From: Joseph Feld <email@hidden>)

  • Prev by Date: How to get from NSMutableData to NSString / URL loading issue
  • Next by Date: Re: How to get from NSMutableData to NSString / URL loading issue
  • Previous by thread: Re: Newbie: Object life within a method scope
  • Next by thread: Re: Newbie: Object life within a method scope
  • Index(es):
    • Date
    • Thread