Jump to content

  • Log In with Google      Sign In   
  • Create Account

Instruments and memory usage going up without any leaks


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 aregee   Members   -  Reputation: 1024

Like
0Likes
Like

Posted 10 March 2014 - 07:45 AM

I launched Instruments for the first time, and had a play around.  I am happy to see that I have no leaks no matter how much I try to stress my application.  To verify that leaks are indeed detected, I removed one 'free()' to see if it detected that leak.  It did as expected.  I am also assuming that 'Live Bytes' and '#Living' are the numbers I am interested in if I want to see if my application is eating memory.

 

What I am observing is, that even if there are no leaks detected, there are groups of memory allocations that go up and up and up.

 

One that steadily increases is 'Malloc 64 Bytes'.  I was wondering about what that could be, since there is nowhere in my code that 'malloc(64)'.  At least not in a steadily fashion.  And it is not leaked!

 

I was thinking that maybe there is a GUI element that is exhibiting this behaviour.  The only GUI element I have that could fit this, is a NSSlider I have to track song position.  That was easily tested: I just paused the song, and the slider would stop updating.  The steady rise of 'Malloc 64 Bytes' stopped too.  Then I dragged the slider, and the number started to go up again.  In fact, I have found that usage of any GUI element exhibits this behaviour for allocations of various amounts of memory.  Nothing is ever leaked.

 

Is this some kind of internal optimisation that I don't need to worry about?  Is there any way I can stop this from happening?  What is really happening?  Will it eventually be freed during the course of my program?

 

If I have a closer look at which part of the program that is allocating this memory, I see an overwhelming amounts allocated from 'QuartzCore'.  Other names I see is 'AppKit', 'Foundation', 'Shortcut' and 'Core*' where '*' is 'Graphics' and 'Image'.

 

Responsible caller for 'QuartzCore' is 'CA::Context::commit_transaction(CA::Transaction*)'.

 

There is no part of my code listed as having allocated any of this memory.

 



Sponsor:

#2 uglybdavis   Members   -  Reputation: 910

Like
2Likes
Like

Posted 10 March 2014 - 04:43 PM

From: http://memo.tv/archive/memory_management_with_objective_c_cocoa_iphone

 

An autorelease pool is an instance of NSAutoreleasePool and defines a scope for temporary objects (objects which are to be autoreleased). Any objects which are to be autoreleased (e.g. objects you send the autorelease message to or created with convenience methods) are added to the current autorelease pool. When the autorelease pool is popped (released) all objects that were added to it are also automatically released. This is a simple way of managing automatic release for objects which are needed temporarily.

E.g. You want to create a bunch of objects for temporary calculations, and instead of keeping track of all the local variables you define and then calling release for all of them at the end of your function, you can create them all with autorelease (or convenience methods) safe in the knowledge that they are going to be released next time the autorelease pool is popped. Note: there is a downside to this which I'll discuss in the Convenience vs Explicit section.

Autorelease pools can be nested, in which case autorelease objects are added to the latest autorelease pool to be created (the pools are stacked in a Last In First Out type stack).

 

Do you have any auto release pools? If so they are probably in a context that doesn't get destroyed (such as main)



#3 aregee   Members   -  Reputation: 1024

Like
0Likes
Like

Posted 11 March 2014 - 06:32 AM

From: http://memo.tv/archive/memory_management_with_objective_c_cocoa_iphone

 

An autorelease pool is an instance of NSAutoreleasePool and defines a scope for temporary objects (objects which are to be autoreleased). Any objects which are to be autoreleased (e.g. objects you send the autorelease message to or created with convenience methods) are added to the current autorelease pool. When the autorelease pool is popped (released) all objects that were added to it are also automatically released. This is a simple way of managing automatic release for objects which are needed temporarily.

E.g. You want to create a bunch of objects for temporary calculations, and instead of keeping track of all the local variables you define and then calling release for all of them at the end of your function, you can create them all with autorelease (or convenience methods) safe in the knowledge that they are going to be released next time the autorelease pool is popped. Note: there is a downside to this which I'll discuss in the Convenience vs Explicit section.

Autorelease pools can be nested, in which case autorelease objects are added to the latest autorelease pool to be created (the pools are stacked in a Last In First Out type stack).

 

Do you have any auto release pools? If so they are probably in a context that doesn't get destroyed (such as main)

 

I tried, but didn't see any difference.  I might have put it in the wrong place, but I noticed some other behaviour too.

 

I was watching the particular 'Malloc(64)' while I was playing a song, and the value just went up for half an hour.  64 bytes here and 64 bytes there doesn't really add up to much over a short duration.  I think it reached 750kB or something.  Then I decided to just let the music play to an end.  A little while later the allocations just dropped from about '#Live' 5000-ish to just 200.  That makes me think it is managed somehow.  And since I was playing the same song for half an hour without ever releasing it (NSInputStream), it really fits NSInputStream more than any GUI elements.  I will have a deeper look into that.  Thank you for your response!  Thinking about it, I think you are right about lacking a well placed autorelease pool.  You are certainly right about me only having an autorelease pool for main.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS