Leaked Memory

Posted:
in macOS edited January 2014
What happens to memory when its leaked from an Application? Does it ever get regained, such as on logout or do you have to restart?

Comments

  • Reply 1 of 17
    amorphamorph Posts: 7,112member
    It's reclaimed by the OS when the application quits.
  • Reply 2 of 17
    So why do you have to add release a [myObject release] method for each object you allocate in the dealloc method? Whats the point if all this memory is reclaimed by the OS?



    BTW, is this the same or different from the way OS 9 handels it. Sorry bout all the questions...
  • Reply 3 of 17
    chychchych Posts: 860member
    You release it because you are a good programmer, even though there is an autorelease pool around your application which is released in the end.



    OS 9 dies a horrible death if you do not maintain memory properly.



    [ 02-03-2003: Message edited by: chych ]</p>
  • Reply 4 of 17
    elricelric Posts: 230member
    Ok so lets say your app doesnt relese memory so the longer you use it the more memory it uses. Now what if the user doesn't quit the app but leaves it open in the background? Starting to sound like windows B.S. to me
  • Reply 5 of 17
    rodukroduk Posts: 706member




    [ 02-03-2003: Message edited by: RodUK ]</p>
  • Reply 6 of 17
    amorphamorph Posts: 7,112member
    [quote]Originally posted by Spiffster:

    <strong>So why do you have to add release a [myObject release] method for each object you allocate in the dealloc method? Whats the point if all this memory is reclaimed by the OS?</strong><hr></blockquote>



    Memory leaks make the application - and possibly other applications - lean more heavily on virtual memory than they need to, leading to reduced performance. If the application runs for a long time, or if the memory leak is significant, it could run out of virtual memory altogether and crash. Also, memory allocation is incredibly slow relative to other operations, and so you want to manage memory well to get decent performance.



    Especially on OS X, there's hardly any reason to quit an application. I leave every app that I use running at all times, and hide them as necessary. Under this sort of use, memory leaks are especially bad.



    [quote]<strong>BTW, is this the same or different from the way OS 9 handels it. Sorry bout all the questions...</strong><hr></blockquote>



    It's the same way that just about every OS handles it, including OS 9. OS 9 gets hit much harder much sooner than OS X does, in terms of performance and reliability, partly because its virtual memory system is so much worse, and partly because it's possible to have a memory leak in a routine that requires actual RAM, in which case the application can run out of memory and crash a lot sooner than they would under OS X. Some particularly bad apps allocate temporary memory in the operating system's space and leak it, leading to system instability.
  • Reply 7 of 17
    123123 Posts: 278member
    [quote]Originally posted by Spiffster:

    <strong>So why do you have to add release a [myObject release] method for each object you allocate in the dealloc method? Whats the point if all this memory is reclaimed by the OS?



    BTW, is this the same or different from the way OS 9 handels it. Sorry bout all the questions...</strong><hr></blockquote>





    Actually, you don't have to release anything (but you really should do it!!!). The longer your app runs, the more memory will be used and unnecessary swapping will occur (as Amorph has explained).



    OS9: The memory manager is buggy. Sometimes, application memory (in the application's space) that you don't free yourself is not reclaimed by the system after the application quits (true memory leak, you'll have to restart the machine to get it back).



    [ 02-03-2003: Message edited by: 123 ]</p>
  • Reply 8 of 17
    scottscott Posts: 7,431member
    Shoot man some of the stuff I've written have sucked up loads of RAM and then nearly crashed the system before it was killed. If you alloc in a double loop you can suck up RAM fast
  • Reply 9 of 17
    [quote]Originally posted by Amorph:

    <strong>Especially on OS X, there's hardly any reason to quit an application. I leave every app that I use running at all times, and hide them as necessary. Under this sort of use, memory leaks are especially bad.</strong><hr></blockquote>



    I think I'm misunderstanding what you said. If "Under this sort of use, memory leaks are especially bad," meaning when you never quit an app, logic would the dictate that you should quit the app so as to not have memory leaks. Yet, you say you never quit an app. My guess is that I'm misunderstanding what you mean.



    So, in OS X, you get less memory leaks if you never quit the app? And, if in OS X you get memory leaks no matter what, then shouldn't you restart the comp every so often? Some claim they have had OS X running for months with no restart. I restart my OS 9 every so often so as to clear up the memory. I was under the impression that there was no longer a need for this with OS X.
  • Reply 10 of 17
    kickahakickaha Posts: 8,760member
    [quote]Originally posted by PooPooDoctor:

    <strong>



    I think I'm misunderstanding what you said. If "Under this sort of use, memory leaks are especially bad," meaning when you never quit an app, logic would the dictate that you should quit the app so as to not have memory leaks. Yet, you say you never quit an app. My guess is that I'm misunderstanding what you mean.



    So, in OS X, you get less memory leaks if you never quit the app? And, if in OS X you get memory leaks no matter what, then shouldn't you restart the comp every so often? Some claim they have had OS X running for months with no restart. I restart my OS 9 every so often so as to clear up the memory. I was under the impression that there was no longer a need for this with OS X.</strong><hr></blockquote>



    GAH! You are *all* screwed up.



    Let's try this again.



    Memory leaks are bad. A memory leak will continue to consume more and more memory as the app continues to run. When the app is quit, all the memory is released.



    Under OS 9, this led to problems *quickly*, so people tended to quit apps they weren't actively using. Unfortunately, OS 9 had a memory control bug that left some memory *not* released under certain conditions, and the only way to get it back was to reboot.



    Under OS X, people tend to leave apps running constantly, because OS X is more robust than 9 was, and less memory fragile. This means that the memory leaks will live longer, and consume more memory over time. The memory manager in OS X is much better about handling extreme amount of memory being used, but it's still cumbersome and slows down the system.



    Bottom line: memory leaks are bad. Period.
  • Reply 11 of 17
    nevynnevyn Posts: 360member
    [quote]Originally posted by Spiffster:

    <strong>So why do you have to add release a [myObject release] method for each object you allocate in the dealloc method? Whats the point if all this memory is reclaimed by the OS?

    </strong><hr></blockquote>



    Because it isn't claimed as quickly as it could be claimed. I had a data acquisition app (on a Doze computer) that ran in a tight little loop - with a leak in the loop. When diagnosing "The computer gives me the blue screen of death" I found that the entire 2GB that was free on the HD was filled with _leaked_ data.



    The actual data was 1MB, and it is discarded almost immediately (it gets counted, averaged, weighted, then chucked). But appearently someone forgot to discard a piece of the data -&gt;Boom. The virtual memory system would keep allocating more and more HD space as paging space and eventually things ground to a halt and died... before the normal 'reclaim the leak because the app quit' time.
  • Reply 12 of 17
    [quote]Originally posted by Kickaha:

    <strong>GAH! You are *all* screwed up. </strong><hr></blockquote>



    In more ways then you care to know. <img src="graemlins/lol.gif" border="0" alt="[Laughing]" />



    Yea... ok... I get it... er... wait... I'm so confused. Can't Apple hire a decent plumber? <img src="graemlins/bugeye.gif" border="0" alt="[Skeptical]" />



    [quote]<strong>The memory manager in OS X is much better about handling extreme amount of memory being used, but it's still cumbersome and slows down the system. </strong><hr></blockquote>



    Perhaps what I don't grasp is the degree of "slow down." I mean, is this really an issue where you should restart OS X, say like every week, or is this "system slow down" something only a numerologist dealing with sub-decimals to the umpteen power would be freaked about?
  • Reply 13 of 17
    [quote]Originally posted by PooPooDoctor:

    <strong>



    Perhaps what I don't grasp is the degree of "slow down." I mean, is this really an issue where you should restart OS X, say like every week, or is this "system slow down" something only a numerologist dealing with sub-decimals to the umpteen power would be freaked about? </strong><hr></blockquote>



    Note that as someone pointed out, leaked memory is reclaimed when an app quits, so you don't need to restart for that.



    Having said that, if you use a lot of beta programs, shareware, etc. and just sleep your machine rather than shutdown then it is probably a good idea to reboot once in a while when you find it convenient.
  • Reply 14 of 17
    kickahakickaha Posts: 8,760member
    Just logging out and back in will quit the offensive apps, and reclaim the space. Rebooting under X only reclaims memory that the kernel is leaking... which it really really shouldn't, and I don't believe it does, from some of the uptimes I've seen.
  • Reply 15 of 17
    Most UNIX systems do not clean up shared memory or semaphores when a process stops.

    Does anyone know if OS X handles these any different?
  • Reply 16 of 17
    [quote]Originally posted by Kickaha:

    <strong>Just logging out and back in will quit the offensive apps, and reclaim the space.</strong><hr></blockquote>



    I was thinking more for tinkerers like myself who might end up with zombie processes, or have services running in the background that might be leaking.



    A logout will usually do the trick but I get nervous when I install beta (or MSFT mouse) drivers for hardware and, besdides, my restart time is negligible.



    The bottom line is, a reboot will not hurt anything other than your geek pride and it might help a variety of things on a regularly updated desktop machine with dodgy beta software being installed left, right and centre (and usually asking for your admin password ).



    The only reboots I object to are the ones I'm forced to do.
  • Reply 17 of 17
    kickahakickaha Posts: 8,760member
    True.



    Log out, reboot, whatever floats your boat.
Sign In or Register to comment.