Memory leak ?
-
Hi all,
I currently have a memory leak problem in the following code:
- (void)parse
{
NSXMLParser *parser = [[NSXMLParser alloc]
initWithContentsOfURL:[NSURL
fileURLWithPath:@"/QuickTime_Tier1_proj.ad"]];
[parser setDelegate:self];
[parser parse];
[parser release];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName attributes:(NSDictionary
*)attributeDict
{
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString
*)elementName namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
}
- (IBAction)test:(id)sender
{
int i;
for(i=0; i<5; i++)
[self parse];
}
When running the test method, the memory usage of the app grows up to
70Mb and stick then at 50MB (before running, the app was at 15 Mb). If
I comment out all the delegate methods, the memory doesn't grows (it
stays around 15Mb). Why is the memory not completely released ?
Thanks for any tips!
Jean -
I have been looking at the memory allocation using the ObjectAlloc tool
and it seems that all allocated objects are correctly released. As Matt
Neuburg wrote, we cannot trust the Activity Monitor numbers for memory
leak so my question is the following: why is the "real memory" column
under the activity monitor growing up to 70Mb and then stays around
50Mb (were it should be 15Mb) ? Is this memory considered as "free" ?
How can I be sure ?
Jean
Le 28 mars 05, à 10:32, Jean Bovet a écrit :> Hi all,
>
> I currently have a memory leak problem in the following code:
>
> - (void)parse
> {
> NSXMLParser *parser = [[NSXMLParser alloc]
> initWithContentsOfURL:[NSURL
> fileURLWithPath:@"/QuickTime_Tier1_proj.ad"]];
> [parser setDelegate:self];
> [parser parse];
> [parser release];
> }
>
> - (void)parser:(NSXMLParser *)parser didStartElement:(NSString
> *)elementName namespaceURI:(NSString *)namespaceURI
> qualifiedName:(NSString *)qName attributes:(NSDictionary
> *)attributeDict
> {
> }
>
> - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
> {
> }
>
> - (void)parser:(NSXMLParser *)parser didEndElement:(NSString
> *)elementName namespaceURI:(NSString *)namespaceURI
> qualifiedName:(NSString *)qName
> {
> }
>
> - (IBAction)test:(id)sender
> {
> int i;
> for(i=0; i<5; i++)
> [self parse];
> }
>
> When running the test method, the memory usage of the app grows up to
> 70Mb and stick then at 50MB (before running, the app was at 15 Mb). If
> I comment out all the delegate methods, the memory doesn't grows (it
> stays around 15Mb). Why is the memory not completely released ?
>
> Thanks for any tips!
>
> Jean
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (<Cocoa-dev...>)
> Help/Unsubscribe/Update your Subscription:
> http://lists.apple.com/mailman/options/cocoa-dev/cocoa-dev-
> <list...>
>
> This email sent to <cocoa-dev-list...>
> -
On Mar 28, 2005, at 3:51 PM, Jean Bovet wrote:> I have been looking at the memory allocation using the ObjectAlloc
> tool and it seems that all allocated objects are correctly released.
> As Matt Neuburg wrote, we cannot trust the Activity Monitor numbers
> for memory leak so my question is the following: why is the "real
> memory" column under the activity monitor growing up to 70Mb and then
> stays around 50Mb (were it should be 15Mb) ? Is this memory considered
> as "free" ? How can I be sure ?
>
You have to understand that the underlying kernel is Un*x/BSD based.
Those pages in memory are marked as free usable to the VM subsystem,
but the pages are still in memory at this point. What this means is
that they are available for the next process that needs them. The VM
subsystem is not going to actively swap them out because that would be
work with no benefit. The next step is either another process is going
to allocate them and use them, or they will be swapped out when some
other process needs to swap some of its pages in or back in. I asked
almost the same question about one of my programs on FreeBSD, a close
relative.
Jim
--
/"\ ASCII Ribbon Campaign .
\ / - NO HTML/RTF in e-mail .
X - NO Word docs in e-mail .
/ \ -----------------------------------------------------------------
<jeh...> http://www.FreeBSD.org The Power to Serve
<jim...> http://www.TheHousleys.net
---------------------------------------------------------------------
Do not meddle in the affairs of dragons, for you are crunchy and taste
good with ketchup. -
Thanks a lot for the explanation. So why the "real memory" column of
the Activity Monitor still count these pages if they are marked as free
? Is there a way to know the number of "used" page ? All we really care
about is how much "used" page our app is using ;-)
Jean
Le 28 mars 05, à 13:14, James Housley a écrit :> On Mar 28, 2005, at 3:51 PM, Jean Bovet wrote:
>
>> I have been looking at the memory allocation using the ObjectAlloc
>> tool and it seems that all allocated objects are correctly released.
>> As Matt Neuburg wrote, we cannot trust the Activity Monitor numbers
>> for memory leak so my question is the following: why is the "real
>> memory" column under the activity monitor growing up to 70Mb and then
>> stays around 50Mb (were it should be 15Mb) ? Is this memory
>> considered as "free" ? How can I be sure ?
>>
>
> You have to understand that the underlying kernel is Un*x/BSD based.
> Those pages in memory are marked as free usable to the VM subsystem,
> but the pages are still in memory at this point. What this means is
> that they are available for the next process that needs them. The VM
> subsystem is not going to actively swap them out because that would be
> work with no benefit. The next step is either another process is
> going to allocate them and use them, or they will be swapped out when
> some other process needs to swap some of its pages in or back in. I
> asked almost the same question about one of my programs on FreeBSD, a
> close relative.
>
> Jim
>
> --
>
> /"\ ASCII Ribbon Campaign .
> \ / - NO HTML/RTF in e-mail .
> X - NO Word docs in e-mail .
> / \ -----------------------------------------------------------------
> <jeh...> http://www.FreeBSD.org The Power to Serve
> <jim...> http://www.TheHousleys.net
> ---------------------------------------------------------------------
> Do not meddle in the affairs of dragons, for you are crunchy and taste
> good with ketchup.


