• 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
Stacks & Memory Management.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Stacks & Memory Management.


  • Subject: Stacks & Memory Management.
  • From: Bill Bumgarner <email@hidden>
  • Date: Sun, 21 Dec 2008 09:15:18 -0800

On Dec 21, 2008, at 8:21 AM, Steve Wetzel 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.

Actually, what Mike said was that you very much *do* need to create separate objects to push 100 objects onto the stack. That cannot be avoided.


The separate instances will either be allocated prior to being pushed:

MyObject *myObject;

myObject = [MyObject objectWithID: @"Bob"];
[stack push: myObject];

myObject = [MyObject objectWithID: @"Fred];

Or they will be copied within your -push: implementation:

...
- (void) push: (MyObject *) anObject
{
MyObject *newObject = [anObject copy];
... stick newObject into your stack data structure. -copy implies -retain...
}



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.

Do not look at the retain counts. Down that path lies madness. Frankly, -retainCount should be removed (or, better, modified to just return rand()).


Start here to understand your first question:

http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Introduction/chapter_1_section_1.html

Then read this to understand memory management:

http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

If you are developing new code, I would encourage you to turn on garbage collection.

b.bum

_______________________________________________

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


  • Follow-Ups:
    • Re: Stacks & Memory Management.
      • From: Scott Ribe <email@hidden>
    • Re: Stacks & Memory Management.
      • From: Robert Marini <email@hidden>
References: 
 >Re: Cocoa-dev Digest, Vol 5, Issue 2186 (From: Steve Wetzel <email@hidden>)

  • Prev by Date: Memory Management Q. 1 and 2
  • Next by Date: Re: Memory Management Q. 1 and 2
  • Previous by thread: Re: Cocoa-dev Digest, Vol 5, Issue 2186
  • Next by thread: Re: Stacks & Memory Management.
  • Index(es):
    • Date
    • Thread