Hidden memory leaks
A system administrator told med that memory leaks can be invisible. i.e. 开发者_StackOverflow中文版all memory used by an application may not be visible in task manager or equivalent tool if the application is leaking memory.
He seemed very sure of this. I've always though that all memory leaks are shown correctly (not in bytes, but that the memory is constantly increasing until there are no more memory in the server) in tools like the task manager (or process explorer)?
Is his statement correct, and if so: Which types of programs can leak memory in this way?
Edit:
I'm not talking about seeing a specific leak, but that the process is consuming more and more memory. According to him, the process will not consume more memory for certain memory leaks.
A memory leak is a situation when a block of memory is marked as occupied exists in the program memory and there's no pointer variable in the program storing the address if that block. Task Manager and similar utilities show the total volume of occupied memory (plus overhead, plus fragmentation) and they have no idea about pointers - they can't inspect the program memory.
This is why leaked memory and just occupied memory the program stores pointers to is indistinguishable for such utilities. So leaking memory "silently" - in a covert way such that memory consumption of the program doesn't increase - is impossible.
It might be possible, depending on compile construction, that the memory is not actually being allocated until it is first accessed. So for instance this script:
while(malloc(50));
could be said to be causing a memory leak - as it just keeps assigning memory until it is all taken. However, if the memory is not actually allocated until it is used, then this would be an 'invisible leak' - although I admit it's stretching the definition of leak ;).
First of all it depends on how you define memory leak. I would normally consider any case where memory has been allocated but no pointers/references remain to it to be a memory leak, not just occasions when an application continually allocates memory without releasing it. (and you probably want a different definition again if there is GC involved)
With this definition no it is not possible to see all memory leaks via the task manager as the process may not give all the memory back to the OS after it is released by the program so you won't necesarrily see every positive or negative change in memory use.
That said any process that is constanly gobbling up memory sure does look suspicious
精彩评论