(no subject)

  • I have a question about unarchiving.

    The following code unarchives an item stored on a stack:
    /* Unarchive the stack top. */
    stacktop = [NSKeyedUnarchiver unarchiveObjectWithData:[stack
    lastObject]];
    By looking at the retainCount of stacktop I conclude that the object
    returned by NSKeyedUnarchiver is returned autoreleased. However, I
    cannot find this mentioned in the documentation.

    Is my conclusion correct or am I mistaken and is this not correct?
    Please, can someone corroborate.
    Thanks in advance.

    Hans van der Meer
  • Am 07.10.2006 um 10:30 schrieb Hans van der Meer:
    > The following code unarchives an item stored on a stack:
    > /* Unarchive the stack top. */
    > stacktop = [NSKeyedUnarchiver unarchiveObjectWithData:[stack
    > lastObject]];
    > By looking at the retainCount of stacktop I conclude that the
    > object returned by NSKeyedUnarchiver is returned autoreleased.
    > However, I cannot find this mentioned in the documentation.

      *never* look at the retain count. Look at the method name. The list
    rules tell us not to restate the memory management rules here, so
    I'll point you at the docs:

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

      Note that "take ownership" means you release it, while if someone
    else has ownership, it means that it's either autoreleased or owned
    by another object. The latter case is worth mentioning since e.g.
    NSArray owns all of its objects, and when you release an NSArray, the
    objects in it are generally released as well. So, request ownership
    using retain (and later release it) if you need an object you don't
    own longer than the owner exists, or longer than the current
    autorelease pool exists.

    > Is my conclusion correct or am I mistaken and is this not correct?
    > Please, can someone corroborate.

      The conclusion is correct, but the method by which you arrived at
    it was wrong. That clarify things? :-)

    Cheers,
    -- M. Uli Kusterer
    http://www.zathras.de
previous month october 2006 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