• 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
Memory Management Q. 1 and 2
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Memory Management Q. 1 and 2


  • Subject: Memory Management Q. 1 and 2
  • From: Nick Rogers <email@hidden>
  • Date: Sun, 21 Dec 2008 22:39:30 +0530

Hi,
While learning to program in cocoa, people usually start out without giving much thought to memory management especially about freeing the used up memory.
I can say so, because I know a few people like that and also I'm one of them.
My focus was on to get started on the project quickly and complete it ASAP.
But now that its almost finished up, I'm forced to think about freeing memory.
These are 2 questions in a series of more upcoming ones.


1. There is an instance variable (NSMutableArray*) in my object, that I use to hold a large number of elements.
Now when I destroy this object, I don't release the array.
Will it have any effect like making the program crash, subsequently?
Especially when I again create the same kind of object again and again fill the array.


2. I'm feeding an object of type HDIR* named dirRoot to the NSOutlineView.
This HDIR can have a number of children of type HDIR* stored in an NSMutableArray * named children (an ivar in HDIR object).
So its a tree.


When I run the program, the Activity Monitor shows the virtual memory increasing as this tree is populated.
After a substantial increase in VM, I stop the tree and then release this dirRoot (HDIR*) object.
But at this time the VM remains the same in Activity Monitor.
The dirRoot may also be retained by some other object, but I have taken care to release those objects as well.
So my question is whether this tree is released and the VM shown in Activity Monitor may not be released back to the system.
OR the tree may not have been released at all?


the dealloc method of HDIR is as follows:
- (void)dealloc
{
	if (children)
	{
		while ([children count])
		{
			HDIR *child = [children lastObject];
			[children removeLastObject];
			[child release];
		}
		[children release];
		children = nil;
	}
	if (fileName)
	{
		[fileName release];
	}
	if (pathName)
	{
		[pathName release];
	}
    [super dealloc];
}

Is there a problem in this method?

Thanks,
Nick
_______________________________________________

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: Memory Management Q. 1 and 2
      • From: mmalc Crawford <email@hidden>
    • Re: Memory Management Q. 1 and 2
      • From: Bill Bumgarner <email@hidden>
    • Re: Memory Management Q. 1 and 2
      • From: Dave DeLong <email@hidden>
  • Prev by Date: Re: Optimizing NSRectFill
  • Next by Date: Stacks & Memory Management.
  • Previous by thread: Re: Cocoa-dev Digest, Vol 5, Issue 2186
  • Next by thread: Re: Memory Management Q. 1 and 2
  • Index(es):
    • Date
    • Thread