Memory Management



  •  So I'm reading this piece about memory management under Apple's "Cocoa" and it seems pretty straight-forward

     But I thought this one example was a bit unusual:

    <font size="2">@interface Penis : NSObject

    {

      float _length;

    }



    +(id)penisWithLength: (float)length;

    -(id)initWithLength: (float)length;



    -(float)length;

    -(float)lengthWhenCold;



    @end



    @implementation Penis



    +(id)penisWithLength: (float)length

    {

      // returns auto-released object.

      // caller NOT responsible for memory management.

      return [[[self alloc] initWithLength: length] autorelease];

    }



    -(id)initWithLength: (float)length

    {

        // caller responsible for memory management.

      if ((self = [super init]))

      {

        _length = length;

      }

      return self;

    }



    -(id)copy

    {

      // could be implemented as

      // return [self retain];

      // since this object is not mutable.



      // caller responsible for memory management.

      return [[Penis alloc] initWithLength: length];

    }



    -(float)length

    {

      return _length;

    }



    -(float)lengthWhenCold

    {

      return _length * 0.25;

    }



    @end
    </font>



  • They forgot this one:

    <FONT size=2>-(float)reportedLength
    {
      return _length + 2.0;
    }</FONT>

    @El_Heffe said:

    autorelease

    Tee hee.


  •  @El_Heffe said:

    So I'm reading this piece about memory management under Apple's "Cocoa" and it seems pretty straight-forward

    TRTWF is expecting to find anything of value on Kuro5hin.  I'm surprised to learn it's still going frankly.



  • It might be an elaboration on Cocoa Words That Sound Dirty But Aren't ( http://www.sticksoftware.com/developer/cocoajoke.html ). Not really funny though.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.