RAM-Usage of an application

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
zztemp
Posts: 24
Joined: Mon Apr 03, 2017 6:58 am

RAM-Usage of an application

Post by zztemp » Thu Aug 02, 2018 11:36 pm

Hello,

I have created a GUI that sits in the systemtray, it get's some computerinformation from the WMI.
It has a secundary runspace that has a never ending while-loop that constantly checks something.

Now the GUI itself mainly just sits in the systemtray after logon of the user. When clicked it will get the WMI information and display it.
When you have triggered it to get the info, the ram-usage goes up with 30+- MB but it never drops back down.

Now my question here is, is there a way (within PS Studio or else) to figure out what parts of you application our using X-amount of RAM?

All in all the application uses about 100 MB , that's not too much, but i wonder if it could be more economical.

Thanks.

User avatar
jvierra
Posts: 13177
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: RAM-Usage of an application

Post by jvierra » Fri Aug 03, 2018 2:16 am

The base workingset for an application running a GUI in PowerShell runs around 100Mb. THis is not the amount of physical memory in use but is the amount of virtual memory allocated. Windows manages this memory and will trim it if necessary.

If you take some time to learn about process memory and how Windows manages this you will see that this number is unimportant most of the time.

A new copy or PS will start with an initial memory of around 85Mb depending one the number of modules autoloaded. It will grow on demand but will not shrink if the system does not need to scavenge memory.

Windows does a thing called working set trimming periodically and grabs back memory if it needs to. My 85Mb PS shows a paged memory at this moment of 51Kb and a peak WS of 2.2Gb. These are limits and not actual usage. Run Performance Monitor to watch how memory is being managed. Tou can also use SysInternals ProcessExplorer to inspect how each component of an application is using memory.

The following will get you started learning about memory in Windows: https://docs.microsoft.com/en-us/window ... management

You can also learn more in depth by reading the Windows NT Internals book. https://www.amazon.com/Windows-Internal ... 0735684189

for performance monitor type "perfmon" at any prompt.

User avatar
zztemp
Posts: 24
Joined: Mon Apr 03, 2017 6:58 am

Re: RAM-Usage of an application

Post by zztemp » Tue Aug 07, 2018 2:18 am

I appreciate the input.
That was quite the rabbit hole ... . The more i read the more it became blurred :/
This topic got me way out of my scope but i picked up a thing or two. However, putting your finger on how much ram my application actually uses isn't really clear. We have the book you are talking about at work but that topic alone is about 200 pages. So it was ignorant from my part to expect a 'simple' answer for this topic.
Having said that, i'm not going to get into the nitty gritty details of RAM. I'm going to assume that the usage is OK and for now, not gonna worry about it too much.

Thanks again.

User avatar
jvierra
Posts: 13177
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: RAM-Usage of an application

Post by jvierra » Tue Aug 07, 2018 2:37 am

The best way to begin to understand memory usage for a process is to run the perfmon tool for that process. You can see how, dynamically, memory is being allocated and released for any process. Just type "perfmon" at any prompt and select "Performance Monitor" from the list.

"Perfmon" is the primary tool used for troubleshooting performance issues. There are many articles written on how to use this tool to find bottlenecks and processes that are causing issues.

https://www.youtube.com/watch?v=591kfPROYbs

Locked