dfsafsafs
dfsafsafs

Reputation:

How to get desktop heap free size?

I want to know what is the desktop heap free size that is left. Is there an API, or a command I can use? I can't install Desktop Heap Monitor - it is out of date for Windows 10. Thank you

Upvotes: 1

Views: 2572

Answers (3)

philu
philu

Reputation: 874

Windbg and Livekd are the tools that can help you here. When you are running livekd, use the !dskheap command.

Upvotes: -1

Grant Wagner
Grant Wagner

Reputation: 25931

I'm not sure how much good it will do knowing how much desktop heap is free. From On the unanswerability of the maximum number of user interface objects a program can create:

Although one could come up with a theoretical maximum number of window classes that can fit in the desktop heap, that number is not achievable in practice because the desktop heap is shared with all other user interface objects on the desktop.

The point is that at any given time, knowing the amount of free desktop heap will not give you any indication of how many more objects you can create.

Typically, when somebody asks this question, the real problem is that they designed a system to the point where desktop heap exhaustion has become an issue, and they need to redesign the program so they aren't so wasteful of desktop heap resources in general.

Ideally you shouldn't need to know how much free desktop heap you have. If it is an issue, you should probably be looking at redesigning your application. The "Error creating window handle" exception and the Desktop Heap says the same thing in other words:

Increasing the Desktop Heap is an effective solution, but that's not the ultimate one. The real solution is to consume less resources...

And provides examples of how to redesign your application:

  • Use TabControls and create the content of each tab on the fly, when it becomes visible;
  • Use expandable/collapsible regions, and again fill them with controls and data only when needed;
  • Release resources as soon as possible (using the Dispose method). When a region is collapsed, it's possible to clear it's child controls. The same for a tab when it becomes hidden;
  • Use the MVP design pattern, which helps in making the above possible because it separates data from views;
  • Use layout engines, the standard FlowLayoutPanel and TableLayoutPanel ones, or custom ones, instead of creating deep hierarchies of nested panels, GroupBoxes and Splitters (an empty splitter itself consumes three window handles...).

Upvotes: 2

Guffa
Guffa

Reputation: 700152

The amount of heap space left is not really an interresting number. The heap space is limited by the amount of memory the application can address or the virtual memory size of the system, which ever comes first.

If you are close to filling the virtual memory size, the system has already swapped out half of it to disk, so at that point you have a system doing way too much disk swapping.

I don't know exactly what you want to find out about the memory usage, but the amount of heap space left will most likely not tell you anything useful.

Upvotes: 0

Related Questions