• 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: "Clark S. Cox III" <email@hidden>
  • Date: Fri, 9 May 2003 08:12:15 -0400

On Thursday, May 8, 2003, at 21:00 US/Eastern, Danny Swarzman wrote:

At 13:10 -0700 5/8/03, Clark S. Cox III wrote:

Example:

@interface MyFoo : NSObject {}
+(MyFoo*)myFoo;
@end

@interface MyBar : MyFoo {}
-(void)someMethodOnMyBar;
@end


....
[[MyBar myFoo] someMethodOnMyBar];
/*Compiler will complain, because return type of myFoo is (MyFoo*), and
MyFoo doesn't respond to -someMethodOnMyBar*/

--

Yeah. The compiler should complain. You wouldn't want to see this in code
that you take over from another programmer - unless you wanted a reason to
fire the person.

Use the compiler to help make the code more clear, not more obscure.

That, of course was a contrived example, how about this:


NSMutableString *myString = [NSMutableString stringWithUTF8String: ...];
[myString appendString: @"blah"];

or

NSMutableArray *myArray = [NSMutableArray array];
[myArray addObject: @"blah"];

This is perfectly valid, legal and well formed code, but if [NSArray array] (and therefore [NSMutableArray array]) were declared as returning an NSArray, then the compiler would complain when you tried to assign the result to an NSMutableArray pointer. This is the whole reason that the factory methods must return (id).




--
http://homepage.mac.com/clarkcox3/
email@hidden
Clark S. Cox, III
_______________________________________________
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:
    • self release
      • From: Wolfgang Ante <email@hidden>
    • Re: Memory Management Mismanaged
      • From: "Dennis C.De Mars" <email@hidden>
References: 
 >Re: Memory Management Mismanaged (From: Danny Swarzman <email@hidden>)

  • Prev by Date: Re: Memory Management Mismanaged
  • Next by Date: Document proxy icon
  • Previous by thread: Re: Memory Management Mismanaged
  • Next by thread: Re: Memory Management Mismanaged
  • Index(es):
    • Date
    • Thread