retain

  • Thanks to everyone who responded to my question, re: Best time to
    init UI elements.  Overloading awakeFromNib worked beautifully.  And
    now, another question:

    If I do this:

      [thePreviewBox setImage:_previewImage] ;

    can I assume that thePreviewBox will retain _previewImage
    automatically, or must I do that myself?  Can I always assume that a
    receiver passed an object will retain?

    Forgive the question if it sounds stupid, I come from a C++
    background :)

    m i k e  m a n z a n o
    <lynx...>
    206.674.3277

    "It's a shame when whole families are torn apart by something as
    simple as wild dogs."
  • Mike Manzano wrote:

    > If I do this:
    > [thePreviewBox setImage:_previewImage] ;
    > can I assume that thePreviewBox will retain _previewImage
    > automatically, or must I do that myself?  Can I always assume that a
    > receiver passed an object will retain?
    >
    Yes.  You should only take care of your own memory management, and you
    should assume that the other objects play by the same rules.

    If you're creating the preview image locally you should have either:

    _previewImage = [[NSImage alloc] init...];
    // ...
    [thePreviewBox setImage:_previewImage] ;
    [_previewImage release];
    or
    _previewImage = [NSImage imageUsingConvenienceConstructorMethod];
    [thePreviewBox setImage:_previewImage] ;

    and that's it (objects created using convenience constructors are
    assumed to be autoreleased).

    See a forthcoming article on the subject at Stepwise for a set of simple
    rules and examples; for a detailed analysis for now see:

    http://www.stepwise.com/Articles/Technical/HoldMe.html

    mmalc.
  • I wrote:
    > See a forthcoming article on the subject at Stepwise for a set of simple
    > rules and examples

    Now at:
    http://www.stepwise.com/Articles/Technical/2001-03-11.01.html

    Thank you to those who have sent feedback already.  I do intend to ad a
    "drilldown" piece on "set" accessor methods to elaborate on the
    different issues there.  The intention of the first article is to keep
    things as simple as possible at the outset, and I didn't want to
    complicate things with a discussion of when to copy, autorelease etc.
    variables.

    mmalc.
previous month april 2001 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            
Go to today