Newbie: How to know whether an object is in autorelease pool

  • Hi,

    Is there any ways to know whether or not an object has been put in an
    autorelease pool?

    I know that class factory puts its instance into autorelease pool.
    But I still don't know whether the other methods like subdataWithRange
    of NSData is put in the pool or not.
    Carbon documentation describes who needs to release the returned
    object, but not Cocoa's.
    I'm always confused with this.

    Thanks,
    norio Ota
  • On Dec 11, 2007, at 9:38 PM, norio wrote:

    > I know that class factory puts its instance into autorelease pool.
    > But I still don't know whether the other methods like
    > subdataWithRange of NSData is put in the pool or not.
    >
    You don't need to know whether an object is in an autorelease pool,
    you just need to know whether you own it...

    > Carbon documentation describes who needs to release the returned
    > object, but not Cocoa's.
    > I'm always confused with this.
    >
    ... Cocoa -- and the Cocoa documentation -- follows a simple set of
    rules given here:

    <http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Tasks/
    MemoryManagementRules.html
    >

    Memory management is only commented on in the documentation if a
    method does not follow these rules.

    mmalc
  • On Dec 11, 2007, at 9:38 PM, norio wrote:

    > I know that class factory puts its instance into autorelease pool.
    >
    Just to address this as a separate point: no, you don't.

    An object you get back from a "convenience constructor" may typically
    be autoreleased, but there are some cases when it may not be (a shared
    singleton object, for example).  To reiterate the point made in the
    previous reply; your only concern should be, do you own the object --
    are you following the rules correctly.

    mmalc
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today