• 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 Managment (copys??)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Memory Managment (copys??)


  • Subject: Re: Memory Managment (copys??)
  • From: Sherm Pendley <email@hidden>
  • Date: Sat, 5 Feb 2005 17:55:18 -0500

On Feb 5, 2005, at 4:38 PM, Coleman Nitroy wrote:

Ok, I am very suprised I got as far as I did without running into a memory issue. Here is my perplexing problem (its probably something so very simple).

If I were to do this

NSMutableArray *array = [[NSMutableArray alloc] init];
SOMEObject *object = [[SOMEObject alloc] init];
for ( i = 0; i < 10; i++ ) {
	[object setSomeProperty: i];
	[array addObject: object];
}

And then print out someProperty for all of the objects in array, I would get the last property only.. so I would get 10, 9's.

The array has ten references to the same object.

 I tried doing:

[array addObeject: [object copy]];

And all I got was 10, 0's. I am baffled. How do I handle this?

I'm guessing that you haven't implement your own -copyWithZone: method in your SOMEObject class. From the docs for the NSCopying protocol:


"If a subclass inherits NSCopying from its superclass and declares additional instance variables, the subclass has to override copyWithZone: to properly handle its own instance variables, invoking the superclass’s implementation first."

sherm--

Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >Memory Managment (copys??) (From: Coleman Nitroy <email@hidden>)

  • Prev by Date: Re: Memory Managment (copys??)
  • Next by Date: Binding and NSPopUpButton selectItemAtIndex
  • Previous by thread: Re: Memory Managment (copys??)
  • Next by thread: Re: Memory Managment (copys??)
  • Index(es):
    • Date
    • Thread