Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 03, 2016, 03:58:14 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: IDEA: Application memory limiter  (Read 5948 times)

vbmark

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 40
    • View Profile
    • Donate to Member
IDEA: Application memory limiter
« on: March 01, 2012, 09:39:29 AM »
Minimum requirement: Prevent any application from using more than X amount of memory.
Bonus: Apply different limits to different applications.

When limit reached options:
1) Automatically close the application.
2) Freeze the application (if possible) and popup notification.
3) Do nothing but notify.
4) Pop up message box asking what to do.

Thanks

kunkel321

  • Supporting Member
  • Joined in 2009
  • **
  • Posts: 464
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #1 on: March 01, 2012, 11:15:02 AM »
I think ProcessTamer http://www.donationc...index.php?board=16.0
might be designed for that(?)

vbmark

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 40
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #2 on: March 01, 2012, 11:26:06 AM »
ProcessTamer is for the CPU and I am looking for something similar but for memory.

Thanks, though.

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 2,925
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #3 on: March 01, 2012, 04:37:05 PM »
Looks like Chameleon Task Manager Pro does something of the sort; see screenshot.

vbmark

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 40
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #4 on: March 01, 2012, 07:03:48 PM »
Chameleon Task Manager Pro costs money and I am looking for something that is free.

Thanks, though.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 2,778
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #5 on: March 02, 2012, 01:28:27 AM »
Hm, I'm a bit worried you need to limit the memory use of any software. The software involved should use, and get, any available memory it needs.
How are you to decide how much memory that application should be using? :-\

If memory usage is an issue, because it is really excessive, you'd optimally signal the makers of that software, and ask them to 'fix' the issue, not limit the application and possibly cripple or crash it.
Switching to some alternative that uses less memory is also a possible solution.

vbmark

  • Participant
  • Joined in 2005
  • *
  • default avatar
  • Posts: 40
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #6 on: March 02, 2012, 06:36:47 AM »
I am a software developer troubleshooting a large application that has a problem with a runaway memory leak.  I cannot always keep my eye on the memory usage and if I don't catch it when it starts to run it eats up my memory, hangs my computer, and I must do a hard reboot.

I don't have time to create this little app myself and I thought it would be simple for someone to make -- just loop through each running process and see if its memory usage is above the set limit.

In my case I know that if the executable hits one gig of working memory then it's running away and will soon consume all that's left.  If I could stop it at one gig it would make my life easier.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #7 on: March 02, 2012, 09:58:07 AM »
Here is a QnD (Quick 'n Dirty) AutoHotkey script that watches an executable name and fires off a message box if memory usage of the process exceeds one gig.  Obviously, change firefox.exe to your required executable name.

Code: Autohotkey [Select]
  1. ExeName := "firefox.exe"
  2. SetTimer, MemWatcher, 10000
  3.  
  4. Return ; End of auto-execute section.
  5.  
  6.  
  7. MemWatcher:
  8. {
  9.     myMem := GetProcessMemoryInfo( ExeName )
  10.     If ( myMem > 1048576 )
  11.     {
  12.         MsgBox, 48, Alert!, Memory exceeded for %ExeName%
  13.     }
  14. }
  15. Return
  16.  
  17.  
  18. GetProcessMemoryInfo( pName ) ; http://www.autohotkey.com/forum/post-223061.html#223061
  19. {
  20.    Process, Exist, %pname%
  21.    pid := Errorlevel
  22.  
  23.    ; get process handle
  24.    hProcess := DllCall( "OpenProcess", UInt, 0x10|0x400, Int, false, UInt, pid )
  25.  
  26.    ; get memory info
  27.    VarSetCapacity( memCounters, 40, 0 )
  28.    DllCall( "psapi.dll\GetProcessMemoryInfo", UInt, hProcess, UInt, &memCounters, UInt, 40 )
  29.    DllCall( "CloseHandle", UInt, hProcess )
  30.  
  31.    list = cb,PageFaultCount,PeakWorkingSetSize,WorkingSetSize,QuotaPeakPagedPoolUsage
  32.    ,QuotaPagedPoolUsage,QuotaPeakNonPagedPoolUsage,QuotaNonPagedPoolUsage
  33.    ,PagefileUsage,PeakPagefileUsage
  34.  
  35.    /*
  36.    cb := NumGet( memCounters, 0, "UInt" )
  37.    PageFaultCount := NumGet( memCounters, 4, "UInt" )
  38.    PeakWorkingSetSize := NumGet( memCounters, 8, "UInt" )
  39.    WorkingSetSize := NumGet( memCounters, 12, "UInt" )
  40.    QuotaPeakPagedPoolUsage := NumGet( memCounters, 16, "UInt" )
  41.    QuotaPagedPoolUsage := NumGet( memCounters, 20, "UInt" )
  42.    QuotaPeakNonPagedPoolUsage := NumGet( memCounters, 24, "UInt" )
  43.    QuotaNonPagedPoolUsage := NumGet( memCounters, 28, "UInt" )
  44.    PagefileUsage := NumGet( memCounters, 32, "UInt" )
  45.    PeakPagefileUsage := NumGet( memCounters, 36, "UInt" )
  46.    */
  47.  
  48.    n=0
  49.    Loop, Parse, list, `,
  50.    {
  51.       n+=4
  52.       SetFormat, Float, 0.0 ; round up K
  53.       this := A_Loopfield
  54.       this := NumGet( memCounters, (A_Index = 1 ? 0 : n-4), "UInt") / 1024
  55.  
  56.       ; omit cb
  57.       If A_Index != 1
  58.          info .= A_Loopfield . ": " . this . " K" . ( A_Loopfield != "" ? "`n" : "" )
  59.    }
  60.  
  61.    ; Return "[" . pid . "] " . pname . "`n`n" . info ; for everything
  62.    Return WorkingSetSize := NumGet( memCounters, 12, "UInt" ) / 1024 ; what Task Manager shows
  63. }

ruskiem

  • Participant
  • Joined in 2014
  • *
  • Posts: 3
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #8 on: August 09, 2014, 10:33:08 AM »
Thank You skwire, but thats not it.
its 2014, yeas, but that can be still very usefull.
i need that too, like ProcessTammer for CPU, we need similar for RAM Memory

even just as simple as that:

"Minimum requirement: Prevent any application from using more than X amount of memory.

When limit reached options:
1) Automatically close the application."

Please anybody know about such thing or can MacGyver it in xx minutes?

Thank You
Waiting for reply
Best Regards!

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,405
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #9 on: August 09, 2014, 02:21:25 PM »

40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,768
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #10 on: August 09, 2014, 03:44:28 PM »
Please anybody know about such thing

IIRC there used to be something called a "job object" where you could do something similar.

My infobase has something from CodeProject that a coder might be able to use for ideas about ways to accomplish it.

Here's the link to the CodeProject page. But from the looks of it, it's a 32-bit solution and it's pretty old.

Can't comment beyond that. The CodeProject page was part of some research I was doing for a client for something I've long since forgotten about. Apologies. :-[


Funny thing...the old Macintosh operations systems (Prior to OSX) used to have that capability. If you requested "info" on an app (equivalent to "properties" in Windows) you got this window (see below) where you could easily set the min/max amount of RAM use allowed per application...

9GetInfoMemory.jpg

With heavyweight graphic apps like Photoshop and Quark you often had to fiddle with those values to find a setting that minimized app crashes on your machine. Otherwise you'd get one of those dreaded "bomb" notifications.

bomb.jpg


Back when 8Mb was considered a full RAM complement, futzing with RAM settings was a big - and necessary -  deal.
« Last Edit: August 09, 2014, 03:59:22 PM by 40hz »

Edvard

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 2,888
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #11 on: August 10, 2014, 03:29:07 PM »
IIRC there used to be something called a "job object" where you could do something similar.

There still is:
http://msdn.microsof...4161%28VS.85%29.aspx
Quote
A job object allows groups of processes to be managed as a unit. Job objects are namable, securable, sharable objects that control attributes of the processes associated with them. Operations performed on a job object affect all processes associated with the job object. Examples include enforcing limits such as working set size and process priority or terminating all processes associated with a job.

No idea where to go from there, but there's example code from the links at that page.

R-X

  • Participant
  • Joined in 2014
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #12 on: October 14, 2014, 07:38:02 PM »
Hi guys,
New user here but exact same requirements as vbmark. I have an application that I know is running away when it hits 1gb RAM. I currently have a solution which I'm running on Windows 7 x64 but I want a better one as described above.

To assist those looking for *something* I use a little app called Usage Monitor which has the capability to monitor a memory level on a given process and take action once that level is hit. I have it executing a batch file which includes a taskkill.exe command to kill off the offending process and a blat.exe command to email me so I can see when this happens (all hours it seems).

The problem with this setup is that the memory limit on the process seems to have to be set every time the process is created and I often forget to set the limit until I notice it has taken all available RAM and made my PC run like a 286. It would also be nice if that util could accept the commands straight into its own menus but it gets the job done and the best improvement to it would be to just monitor for when that process starts so I don't have to set it every time.

I had a bit of a look for other tools which brought me here but haven't found anything else so far.

Enjoy
« Last Edit: October 14, 2014, 07:50:51 PM by R-X »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,664
    • View Profile
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #13 on: October 16, 2014, 09:02:51 AM »
New user here but exact same requirements as vbmark.

Hi, R-X, and welcome to the DonationCoder forums.   :)  My script from above can easily be adapted to do what you want.  It current just shows a message box when the memory limit is exceeded but that can be changed to kill a process.  Are you familiar with AutoHotkey scripting?

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,405
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: IDEA: Application memory limiter
« Reply #14 on: October 16, 2014, 10:02:11 AM »
NANY 2015 is coming up, this might be time for me to add features to Process Piglet tool that would do this kind of thing.
It would assist me if you could try it and tell me how you'd like me to add the new features.