 |
 |
What is a memory leak?
|
 |
|
 |
|
Grizzled Veteran
Join Date: Nov 2002
Location: London, UK
Status:
Offline
|
|
Heard this mentioned a few times, but don't know what it means.
I'm running bittorrent occasionally and after a few hours the whole system goes really slow and programs quit on opening or just lock up. It was suggested that BT has a memory leak, but I've no idea what that means.
Does it go away when you quit the program? I've been rebooting when it gets bad, but is there a way to fix it without the reboot?
Thanks for the help,
J.
|
|
By all means let's be open-minded, but not so open-minded that our brains drop out - Richard Dawkins
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 1999
Location: Madison, WI
Status:
Offline
|
|
Ohh, thanks for asking this, I have an idea what it is, but am not positive.
/me clicks the "email Notification" box
-Owl
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Sep 2000
Location: Torrance, CA
Status:
Offline
|
|
A piece of software launches, gets loaded into memory and when quit stays in that area of memory. You need to restart to clear it up.
Only way to fix it would be for them to fix it I think. 10.2.6 supposedly has a memory leak so if true it's up to Apple.
|
|
|
| |
|
|
|
 |
|
 |
|
Moderator 
Join Date: Jan 2001
Location: Atlanta, GA
Status:
Offline
|
|
From Webopedia:
A bug in a program that prevents it from freeing up memory that it no longer needs. As a result, the program grabs more and more memory until it finally crashes because there is no more memory left.
Although the thought of RAM chips oozing all over the motherboard is kinda cool. 
|
|
|
| |
|
|
|
 |
|
 |
|
Professional Poster
Join Date: Nov 2000
Location: Tasmania, Australia
Status:
Offline
|
|
Originally posted by derekn:
A piece of software launches, gets loaded into memory and when quit stays in that area of memory. You need to restart to clear it up.
Not quite.
When a program terminates, the Operating System frees up all the memory it was using (at least in unix-type OS like OS X).
While programs are running, they grab additional memory whenever they need it. Sometimes there are bugs in the programs such that they do not release the memory when they are finished with it. If a program keeps grabbing memory and doen't release it when it's finished with it, that is a memory leak.
Memory leaks can be easily fixed by killing the offending program, so long as you do it before the system runs out of memory, and other programs are affected (with the exception of processes that cannot be safely killed, such as OS components).
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Apr 2001
Location: The bottom of Cloud City
Status:
Offline
|
|
Strange thing is I always heard that with OSX memory leaks would be a thing of the OS9 days and we would never have that problem with a UNIX OS.
|

"Ahhhhhhhhhhhhhhhh"
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Jul 2002
Location: Leiden, Netherlands
Status:
Offline
|
|
Originally posted by Severed Hand of Skywalker:
Strange thing is I always heard that with OSX memory leaks would be a thing of the OS9 days and we would never have that problem with a UNIX OS.
Yes because in the OS 9 days when a program had a memory leak, when you quitted the programm the OS might not free the memory. In X the OS releases the memory thos programms did not free.
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Mar 2001
Location: San Diego
Status:
Offline
|
|
Severed Hand of Skywalker:
The only why to be safe from memory leaks is to have the OS limit the amount of Memory an Application can use. I believe MacOS X only allows an app to address 4 Gigs of ram. The difference between MacOS X and 9 is the protected memory. An OS 9 app with a memory leak could easily crash the whole system since it could write over other apps memory space. Under MacOS X the app can't do that but it can take up as much ram as the OS allows it to. So if you have an App that has taken up all of your 512MB it would just page most other apps to disk and it would become very slow. Depending on other applications memory demand and how bad the leak is it could page so bad that the machine would become unresponsive. You can make the OS handle this better by having it watch processes and terminating them depending on how they act.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
Memory leaks:
When a program needs to store something, it allocates memory. It is supposed to then free that memory when it no longer needs it. Due to coding or design errors, sometimes a program will allocate but not free memory, eating up more and more memory as it remains open for longer. In Mac OS 9, this would eventually lead to all system memory being used up, resulting in the system being Very Slow or crashing. In Mac OS X, programs can still leak - there is no way to prevent bad programming - but once an application is quit, the OS frees ALL memory that that program had allocated. So, quitting Bittorrent should free up all the memory and return the computer to its normal speed.
|
|
[vash:~] banana% killall killall
Terminated
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Nov 2002
Location: London, UK
Status:
Offline
|
|
Thanks for such informative answers. I'll monitor bittorrent and see how it goes.
Cheers,
J.
|
|
By all means let's be open-minded, but not so open-minded that our brains drop out - Richard Dawkins
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
To continue beating on a dead horse...
WHAT'S A MEMORY LEAK?
1. Application grabs some memory.
2. Application quits and doesn't return the memory.
3. The next application that starts up "could" see less available memory unless the operating sytem is careful and reclaims it. The memory will appear to be shrinking. Therefore the leak analogy.
CAN THIS HAPPEN IN OSX?
Absolutely!
SO WHY IS OSX BETTER THAN OS9?
Because OS9 was horrible at reclaiming space and in many instances you would get a crash.
OSX is carefull has highly effecient house cleaning (since it's a Unix) and will not crash on you. If any thing, it will quit running the application and protect your system data and other running programs. So OSX is way better than OS9 in this matter. OSX is as good as it currently gets for this kind of issue.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
is it possible to have a processor leak? because if I leave mlMac open for about an hour, it starts to use more and more of my cpu, in the red region in menu-meters (what it calls 'system load'). If I leave it on overnight and it manages not to crash, it's using about 40% of my 2x1ghz, and everything else is quite unresponsive for about 60 seconds at a time. Can anyone explain this to me?
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: May 2001
Status:
Offline
|
|
Originally posted by Uncle Skeleton:
is it possible to have a processor leak? because if I leave mlMac open for about an hour, it starts to use more and more of my cpu, in the red region in menu-meters (what it calls 'system load'). If I leave it on overnight and it manages not to crash, it's using about 40% of my 2x1ghz, and everything else is quite unresponsive for about 60 seconds at a time. Can anyone explain this to me?
It's possible to write shitty inefficient software.
File a bug with the developers.
As for why everything else is unresponsive, I've noticed that dynamic_pager frequently blocks everything if you're doing something that involves swapping large numbers of pages in and out of RAM.
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
1. Launch the Terminal application. Type in "top" without the quoutes.
2. Find out which processes are hogging up the CPU.
3. Come back to this forum and tell us who the offender is.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
yeah it was mlMac that was using the cpu (and nothing else). I don't understand how a user app could be hogging system-owned resources. Anyway, I left it running this morning and when I get home I'll snoop around. If you could give me some more things to check that would help. All I can think of now is to check the RAM usage
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Apr 2000
Location: Belgium
Status:
Offline
|
|
Originally posted by Uncle Skeleton:
is it possible to have a processor leak?
The same way it is possible to forget to release unused memory, it is possible to forget to close unused threads if you're a really clumsy programmer. Threads are subprograms that run in the background, and each thread takes some CPU usage. Try monitoring the number of threads mlMac has (the #TH column in top).
|
|
PowerMac G4 400MHz/832MB/60GB
AlBook G4 15" 1.25GHz/1.5GB/60GB
Athlon 64 3500+/Asus A8N-SLI Premium/2GB RAM/990GB HD/GF7800GT 512
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
Originally posted by Uncle Skeleton:
yeah it was mlMac that was using the cpu (and nothing else). I don't understand how a user app could be hogging system-owned resources. Anyway, I left it running this morning and when I get home I'll snoop around. If you could give me some more things to check that would help. All I can think of now is to check the RAM usage
If you that mlMac is the offender then your choices are (as far as I can tell):
1. Use an alternative application.
2. Complain to the developers
3. I believe that there's a way to assign a processor priority to certain apps. I know this is possible with the typical Unix processes but I haven't fiddle with it in many years. I would just create a new post (in this forum) and ask for feedback on setting process priorities.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
actually what I do is force quit mlMac when I need to use the machine again, and the mlnet daemon keeps running in the background. I was just curious about how such a thing could happen.
here's top:
Code:
Processes: 53 total, 3 running, 50 sleeping... 166 threads 13:35:32
Load Avg: 1.49, 1.34, 1.18 CPU usage: 6.8% user, 56.5% sys, 36.7% idle
SharedLibs: num = 121, resident = 8.34M code, 648K data, 1.73M LinkEdit
MemRegions: num = 216111, resident = 637M + 2.15M private, 105M shared
PhysMem: 106M wired, 601M active, 302M inactive, 1009M used, 15.2M free
VM: 6.24G + 75.4M 142478(1) pageins, 1604147(286) pageouts
PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE
3542 top 54.7% 0:47.57 1 15 26 2.38M 316K 2.67M 15.6M
3541 tcsh 0.0% 0:00.04 1 10 16 332K 580K 776K 5.73M
3540 sshd 0.0% 0:00.03 1 8 34 104K 1.16M 408K 16.8M
3538 sshd 0.0% 0:00.43 1 14 34 96K 1.16M 1004K 16.8M
3502 mlnet 6.3% 33:21.80 2 28 199 39.1M+ 2.68M 40.9M+ 46.7M
3492 mozilla-bi 0.5% 3:18.31 12 180 539 456K 1.31M 1.14M 325M
3391 mlMac 52.9% 94:39.97 3 78 211252 585M+ 89.0M+ 36.1M- 2.50G+
3379 Terminal 0.0% 0:10.25 2 62 116 168K 1.02M 592K 75.2M
etc
so it looks like there is a hefty memory leak in addition to the processing hog. I didn't see it before because I usually use top -d.
The thing I'm still wondering about is the fact that mlMac is the one using up the cpu, and it should run as my user (no root passwords given or anything), yet the usage is all from 'system', not 'user'
|
|
|
| |
|
|
|
 |
|
 |
|
Senior User
Join Date: Oct 2000
Location: Lawrence, KS
Status:
Offline
|
|
Originally posted by Uncle Skeleton:
actually what I do is force quit mlMac when I need to use the machine again, and the mlnet daemon keeps running in the background. I was just curious about how such a thing could happen.
here's top:
Code:
Processes: 53 total, 3 running, 50 sleeping... 166 threads 13:35:32
Load Avg: 1.49, 1.34, 1.18 CPU usage: 6.8% user, 56.5% sys, 36.7% idle
SharedLibs: num = 121, resident = 8.34M code, 648K data, 1.73M LinkEdit
MemRegions: num = 216111, resident = 637M + 2.15M private, 105M shared
PhysMem: 106M wired, 601M active, 302M inactive, 1009M used, 15.2M free
VM: 6.24G + 75.4M 142478(1) pageins, 1604147(286) pageouts
PID COMMAND %CPU TIME #TH #PRTS #MREGS RPRVT RSHRD RSIZE VSIZE
3542 top 54.7% 0:47.57 1 15 26 2.38M 316K 2.67M 15.6M
3541 tcsh 0.0% 0:00.04 1 10 16 332K 580K 776K 5.73M
3540 sshd 0.0% 0:00.03 1 8 34 104K 1.16M 408K 16.8M
3538 sshd 0.0% 0:00.43 1 14 34 96K 1.16M 1004K 16.8M
3502 mlnet 6.3% 33:21.80 2 28 199 39.1M+ 2.68M 40.9M+ 46.7M
3492 mozilla-bi 0.5% 3:18.31 12 180 539 456K 1.31M 1.14M 325M
3391 mlMac 52.9% 94:39.97 3 78 211252 585M+ 89.0M+ 36.1M- 2.50G+
3379 Terminal 0.0% 0:10.25 2 62 116 168K 1.02M 592K 75.2M
etc
so it looks like there is a hefty memory leak in addition to the processing hog. I didn't see it before because I usually use top -d.
The thing I'm still wondering about is the fact that mlMac is the one using up the cpu, and it should run as my user (no root passwords given or anything), yet the usage is all from 'system', not 'user'
There's something pretty screwy going on if "top" is consuming that much CPU.
I would, run the disk utility and see what comes up. This not typical behavior. On my 800 MHZ iMac, the top command is always under 10%.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
yeah it usually is for me too. I attribute this to the fact that it was running remotely through ssh. top -d through ssh was under 1%, but it didn't show anything useful. So I'm not going to worry about that
but does anyone know about the system cpu usage question?
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Nov 2001
Location: Trafalmadore
Status:
Offline
|
|
It is the 2.5g of virtual memory that is being used by mlMac that's probably causing the slowdown. You are probably downloading several large files at once. If you download a 650mb file via mlMac, it will create a file of that size in its temp folder, even if only 1kb is downloaded. It probably retains a lot of the file it has downloaded in memory, then periodically writing it to disk. I have never seen cpu% that high with that program.
I hope that's a dual cpu you got there, as your %s add up to greater than 100%. If it's a single, your system is hosed somehow.
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
yes, it's a dual 1ghz quicksilver
it's strange that I would get this behavior (reproducibly) and you wouldn't. What kind of load do you put on it? I have about 40 downloads open at a time, of which about 4 are active at any one time.
And it's impossible that it's related to the functioning of the program, because it's mlMac (the cocoa gui), not mlnet (the unix app) that is the hog (and leak). If I force quit mlMac, mlnet continues at the same performance level, with no memory leak and no cpu hogging. If I then reopen mlMac, it (mlMac) begins to leak and hog again. I suppose it would be possible for searches done with mlMac to leak memory, but I don't leave them open (I can only assume that the searching is aborted when the window is closed). This morning is the first time I opened mlMac and did no searches, just left it running. and it still leaks.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Sep 2001
Location: Chile
Status:
Offline
|
|
Bittorrent does have some sort of leak or it just works like that. According to a friend of mine, Bittorrent on WinXP can also render the system slow because of it's paging, so it's either a low level leak, or it just works like that.
|
:: frankenstein / lcd-less TiBook / 1GHz / radeon 9000 64MB / 1GB RAM / w/ext. 250GB fw drive / noname usb bluetooth dongle / d-link usb 2.0 pcmcia card / X.5.8
:: unibody macbook pro / 2.4 Ghz C2D / 6GB RAM / dell 2407wfp - X.6.3
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
"Processor leaks" are possible, but the programmer would have to be extremely... well, stupid. What's more likely is that the system is wasting time dealing with all the leaked memory 
|
|
[vash:~] banana% killall killall
Terminated
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: Dec 1999
Location: Utah
Status:
Offline
|
|
It's when you drink a lot, and wake up the next day in a strange place, usually naked, or covered in something. Also, you can't remember how or why you are there.
|
|
|
| |
|
|
|
 |
|
 |
|
Admin Emeritus 
Join Date: Oct 1999
Location: Zurich, Switzerland
Status:
Offline
|
|
Originally posted by DaGuy:
3. I believe that there's a way to assign a processor priority to certain apps. I know this is possible with the typical Unix processes but I haven't fiddle with it in many years. I would just create a new post (in this forum) and ask for feedback on setting process priorities.
Yeah, renicing. Find the process ID in top or ps -aux, and then type
where "x" is the priority you want to assign (from -20 [not nice to other processes -- hogs CPU] to 20 [very nice, put on the back burner]; set to 0 to return to default) and y is the process ID.
tooki
|
|
|
| |
|
|
|
 |
|
 |
|
Junior Member
Join Date: Aug 2001
Location: Austria
Status:
Offline
|
|
|
|
|
m@
|
| |
|
|
|
 |
|
 |
|
Mac Elite
Join Date: May 2002
Status:
Offline
|
|
Because to launch a process with a certain priority, you type "nice processname"
Hence the verb "to nice", and changing the priority of something already running is "renicing".
|
|
[vash:~] banana% killall killall
Terminated
|
| |
|
|
|
 |
|
 |
|
Clinically Insane
Join Date: Nov 1999
Status:
Offline
|
|
Using up processor time like mad is generally not caused by memory leaks.
Quick explanation. Computers have a thing called memory. There's only so much memory to go around, no matter what machine you have.
Programs store data, usually in what are called variables. Each variable takes up a certain chunk of memory. Now, some programs already know exactly how much memory they are going to need to use, as soon as they start up. These use a thing called static allocation; that is, all the memory they need is allocated (just a fancy term for "set aside") for that program right when it starts, and that amount of memory never changes (thus, it is "static"). These kinds of programs generally present no problems.
However, many programs have no way of knowing exactly how much memory they will need. Web browsers make a good example of this; to know how much memory they would need, they would need to know exactly what pages you intended to view, at what time, in what order, and everything that would be on the page. Since psychic computers don't exist, programmers instead resort to a thing called dynamic allocation. This just means that programs can grab memory as they need it. However, there's a catch to this: since they grabbed it themselves, they have to let it go when they're done with it. We often call this freeing memory, because the function that does this in Unix is called "free".
There are many methods by which one could free memory. Some languages, like C, make you free your memory manually, just as you allocated it manually. Some other languages use a trick called garbage collection, which periodically looks for memory that's not being used and then frees it.
In any case, memory leaks are what happen when a program doesn't free its memory at the proper time (such as when you don't use it anymore). Rather than memory usage going up and down (but generally staying about the same), memory use keeps going up, because the program grabs memory and doesn't let it go. The sad part is, much of the extra memory is just wasted, because the program doesn't know that it can use all the extra memory it's grabbed (because it was supposed to have freed that memory). If you let a program leak too long, the machine will run out of memory. When that happens, the program will probably crash, and there's a fairly decent chance of taking the rest of the system with it.
|
|
You are in Soviet Russia. It is dark. Grue is likely to be eaten by YOU!
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 2002
Location: Seattle, WA
Status:
Offline
|
|
Originally posted by Millennium:
Using up processor time like mad is generally not caused by memory leaks.
then where does mad proc usage usually come from? (I think in my case it is the memory leak)
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 1999
Location: Madison, WI
Status:
Offline
|
|
Originally posted by SMacTech:
It is the 2.5g of virtual memory that is being used by mlMac that's probably causing the slowdown. You are probably downloading several large files at once. If you download a 650mb file via mlMac, it will create a file of that size in its temp folder, even if only 1kb is downloaded. It probably retains a lot of the file it has downloaded in memory, then periodically writing it to disk. I have never seen cpu% that high with that program.
I hope that's a dual cpu you got there, as your %s add up to greater than 100%. If it's a single, your system is hosed somehow.
Uhhhhh, MLmac is a GUI for mlnet (mldonkey)
It runs the mldonkey daemon and then controls it.
The size of the downloaded files will not effect what *mlmac* needs for memory, mlmac dont even write the file to the disk, it just checks mldonkey to see how much is downloaded!
-Owl
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Nov 1999
Location: Madison, WI
Status:
Offline
|
|
Originally posted by Uncle Skeleton:
then where does mad proc usage usually come from? (I think in my case it is the memory leak)
Running a commands in quick succession.
According to the theory that Memory leaks only cause high CPU usage, then most of todays games are leaking like like... well you get the idea.
But yeah, with mlmac, it has to talk to the daemon every so often, maybe the refresh time is really high (every second or something).
And who knows how efficient his code is, maybe it runs long blocks every time it updates.
Though if it does seem to progressively increase its amount of processor usage, then it very well could be a memory leak.
-Owl
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|