• 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: Memory Management Mismanaged
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory Management Mismanaged


  • Subject: Re: Memory Management Mismanaged
  • From: Danny Swarzman <email@hidden>
  • Date: Thu, 8 May 2003 11:26:19 -0700

At 3:00 -0700 5/8/03, Marcel Weiher wrote:
[SNIP]
>
>> For example,
>>
>> + (MyFoo*) myFoo
>> {
>> MyFoo* aFoo = [[[myFoo alloc] init] autorelease];
>> return aFoo;
>> }
>

Is it '[MyFoo alloc]' ?

>Three minor nits:
>
>1. Don't use a static return type, this will break for subclasses. Use
>id
>2. For the same reason, use 'self' to refer to the current class
>3. I don't think the temporary variable is buying you anything here, so:
>
>+myFoo
>{
> return [[[self alloc] init] autorelease];
>}
>
>
Can you provide an example of how the first example breaks in a sub-class?
>
>> Now you can say...
>>
>> MyFoo* newFoo = [MyFoo myFoo]; // this guy will die in the next
>> event cycle
>
>More accurate and simpler: // I am not responsible
>for releasing
>this guy.
>
>> So, if you want to keep the object longer than one event cycle, do this
>> instead:
>>
>> MyFoo* newFoo = [[MyFoo myFoo] retain];
>
>Possibly easier:
>
> [self setFoo:[MyFoo myFoo]];
>
>
Wouldn't this snippet be likely to appear outside of the definition of
MyFoo? So who is 'self' here?

-Danny Swarzman
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Memory Management Mismanaged
      • From: "Clark S. Cox III" <email@hidden>
    • Re: Memory Management Mismanaged
      • From: Marcel Weiher <email@hidden>
References: 
 >Re: Memory Management Mismanaged (From: Andrew Duncan <email@hidden>)
 >Re: Memory Management Mismanaged (From: Marcel Weiher <email@hidden>)

  • Prev by Date: Dock Icon Help
  • Next by Date: Re: Memory Management Mismanaged
  • Previous by thread: Re: Memory Management Mismanaged
  • Next by thread: Re: Memory Management Mismanaged
  • Index(es):
    • Date
    • Thread