Re: Cocoa-dev Digest, Vol 5, Issue 2186
Re: Cocoa-dev Digest, Vol 5, Issue 2186
- Subject: Re: Cocoa-dev Digest, Vol 5, Issue 2186
- From: "Michael Ash" <email@hidden>
- Date: Sun, 21 Dec 2008 12:42:16 -0500
On Sun, Dec 21, 2008 at 11:21 AM, Steve Wetzel <email@hidden> wrote:
> Thanks Mike, I thought about it a long time before posting, then posted,
> then when going to bed realize the first part of what you said. I don't
> need to create separate instances to push 100 objects onto the stack.
Well actually no, you *do* need to create separate instances. What you
don't need to do is create separate local variables. This may just be
a terminology problem, but then again knowing the right terminology
helps when thinking about things and *definitely* helps when talking
about them to other people.
An instance is an object. If you create two objects, you have created
two instances. A pointer is just a variable which may (or may not)
point to an instance. The same variable can point to more than one
instance (although only one at a time). The same instance can be
pointed to by multiple pointers. To illustrate:
NSString *str = @"hello";
str = @"world";
You have two NSString instances and one NSString* variable.
NSString *str1 = @"hello";
NSString *str2 = str1;
Here you have one NSString instance and two NSString* variables both
pointing to it. And if you then do this:
str1 = @"world";
Now you have two instances and two pointers each pointing to one of
them. str1 points to @"world" and str2 points to @"hello". This is
analogous to the situation you have when passing objects to your
stack.
> NOW I am trying to get my head around memory management with my little
> stack. If anyone has insights and wants to share them feel free. Instead
> of posting a question I think I will load up my little app, look at retain
> counts, and try to figure out how to stop all my memory leaks.
Retain objects as you add them, (auto)release as you remove them, and
release everything you contain when you're destroyed.
Or better yet, just use an NSMutableArray for your storage, and let it
handle the memory management of the objects you put into it.
Mike
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden