views:

155

answers:

4

OK, this may sound weird, but here goes.

There are 2 computers, A (Pentium D) and B (Quad Core) with almost the same amount of RAM running Windows XP.

If I run the same code on both computers, the allocated private bytes in A never goes down resulting in a crash later on. In B it looks like the private bytes is constantly deallocated and everything looks fine.

In both computers, the working set is deallocated and allocated similarly.

Could this be an issue with manifests or DLLs (system)? I'm clueless.

Also, I compiled the executable on A and ran it on B and it worked.

Note:

I observed the utilized memory with Process Explorer.

Question:

During execution (where we have several allocations and deallocations) is it normal for the number of private bytes to be much bigger (1.5 GB vs 70 MB) than the working set?

A: 

Memory leaks can be unpredictable and difficult to pin down. Since you have an IDE on the computer with the memory leak, and you are able to debug the process whose memory is increasing, traditional debugging methods on the bad process would be my only suggestion. You can't use valgrind since you aren't on *nix, but perhaps you should take a look at http://stackoverflow.com/questions/413477/is-there-a-good-valgrind-substitute-for-windows .

Reinderien
@Reinderien: Yes. Why?
Jacob
A: 

It could be a difference in fragmentation. For example, one might be using the small block heap and the other might not. The small block heap can help deal with fragmentation due to small allocations.

Mark Wilkins
+1  A: 

Virtual Address Space, Private Bytes and Working Set are 3 totally different aspects of your application.

  • Private Bytes is the memory currently being used by your application.
  • Working Set is the part of the memory that is currently loaded in RAM. The rest is swapped out in the page file.
  • Virtual Address Space is the highest memory address that is ever being used by your application. Fragmentation may cause the Virtual Address Space to be much larger than the Private Bytes.

It is a typical misconception to think that the limit for Private Bytes is 2GB (for non-largeaddressaware 32-bit applications). 2GB is actually the limit for the Virtual Address Space. Fragmentation causes the limit for Private Bytes to be less. How much this is depends on the application. In my application I start to have problems around 1.7-1.8GB.

See http://shsc.info/WindowsMemoryManagement for a more thorough explanation.

Now this still doesn't explain the difference between your two computers. It's quite difficult to see what the actual cause of this difference is, but it might help looking at the 'aspects' in which they are different, and the first thing I see is the number of processors/cores. Does your application use multi-threading? Could there be a synchronization problem between your threads that only pops up on the quad-core system?

Patrick
@Patrick: Thanks for the detailed response. Multithreading has been switched off, and the problem arises on `A`, the dual-core Pentium D.
Jacob
+1  A: 

The fact that a memory leak (increasing private bytes) doesn't have an effect on working set is no surprise. The working set size is determined by the number of memory pages the application has touched recently. Private bytes is the amount of memory that a process has allocated (and not shared with other processes). If an application is forgetting to free objects that it is no longer using (a memory leak), then it's private bytes will not go down, but the working set will because it's not actively using that memory. See http://technet.microsoft.com/en-us/library/cc780836.aspx for details on the types of statistics for resources that Windows can track for a process.

You might want to look at the versions of the DLLs loaded by the application on each machine - it could be that a patch or service pack needs to be installed on the machine with the memory leak to fix the problem. Process Explorer can also show details of the DLLs loaded in a process.

Michael Burr
True, but from the performance on the other computer, it looks like the application is not forgetting to free objects, correct?
Jacob
Also, I think the issue has to be the DLLs since I used the executable from `A` and ran it on `B` and it worked fine.
Jacob
It needn't be a leak, look at firefox when you have 200+ tabs open and just started something else that used a bunch of RAM, some time, it's RSS will only consist of memory it's touched recently or should unless the your OS's VMM really sucks...
Spudd86
@spudd86: you're right that there might not be a leak, if that memory that's not in the workin set is still reachable and usable by the application, but just hasn't been recently for whatever reason. However, that doesn't sound like Jacob's situation, and I don't think I really said that memory leaks are the only way that the memory might behave this way - just that a leak might easily (or even likely) show this behavior.
Michael Burr