Posts: 1,000
Threads: 253
Joined: Feb 2008
I have an automation machine running a lot of various scheduled tasks by calling QM functions throughout the day.
QM memory usage will continue to grow and grow (it does sometimes go down), but eventually it will start throwing errors about not having enough memory to run functions.
When trying to close QM it will have an error about not having enough memory to save the file.
Is there something I can do to free up QM memory when a function completes or is there something else that is at play here?
It is a little troublesome because it always does it when I take a day off...so then I get a call about things not working.
-jim
Posts: 12,092
Threads: 142
Joined: Dec 2002
Normally should not grow. On my PC QM often runs several days, and memory usage never grows above 20 MB.
Maybe some macros allocate and don't release memory. QM functions and variables (str, ARRAY, COM interface and other) release memory automatically. With some functions, eg Windows API functions, need to explicitly release memory, close handle, etc.
Of course can be a bug in some QM function too. Or in a dll or COM component.
If you have many macros, it is difficult to find memory leaks. I'll try to create a memory leak detector for QM.
If you suspect some macros, try to run them in separate process, if possible.
Posts: 1,000
Threads: 253
Joined: Feb 2008
Is there a way to force QM to restart if memory goes above a threshold?
-jim
Posts: 12,092
Threads: 142
Joined: Dec 2002
Function
GetQmMemoryUsage
;/
function#
;Returns QM memory usage, KB.
;It is what you see in Task Manager, "Commit Size" column.
PROCESS_MEMORY_COUNTERS z.cb=sizeof(z)
if GetProcessMemoryInfo(GetCurrentProcess &z sizeof(z))
,ret z.PagefileUsage/1024
Posts: 5
Threads: 1
Joined: Apr 2018
Hello,
I tried to use this function to get memory of another process using an int but no luck.
int cors=ProcessNameToId2("CorsairLink4.exe" 0 1)
if(cors)
How can I get the memory of another process??
Rob
Posts: 12,092
Threads: 142
Joined: Dec 2002
05-14-2019, 06:52 PM
(This post was last modified: 05-15-2019, 04:31 AM by Gintaras.)
Function
GetProcessMemoryUsage
;/
function# pid
;Returns process memory usage, KB.
;It is what you see in Task Manager, "Commit Size" column. Or in Process Hacker, "Private bytes" column.
;pid - process id. See <help>ProcessNameToId</help>, <google>GetWindowThreadProcessId</google>.
__Handle hp=OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION|PROCESS_VM_READ 0 pid)
if(hp=0) end ES_FAILED 16
PROCESS_MEMORY_COUNTERS z.cb=sizeof(z)
if GetProcessMemoryInfo(hp &z sizeof(z))
,ret z.PagefileUsage/1024
Posts: 5
Threads: 1
Joined: Apr 2018
This works for most processes, however for a process like iexplore.exe, I am only able to get the pid of "iexplore.exe", not "iexplore.exe *32".
Using "int iexplore=ProcessNameToId("iexplore.exe *32" 0 1)" returns 0.
Since iexplore.exe and iexplore.exe *32 have different PID assigned, how can I choose or select which to grab the memory for??
------------------------------------------------------------------------------------------------------------------
function# pid
pid=ProcessNameToId("iexplore.exe" 0 2)
;Returns process memory usage, KB.
;It is what you see in Task Manager, "Commit Size" column. Or in Process Hacker, "Private bytes" column.
;pid - process id. See <help>ProcessNameToId</help>.
__Handle hp=OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION|PROCESS_VM_READ 0 pid)
if(hp=0)
end ES_FAILED 16
PROCESS_MEMORY_COUNTERS z.cb=sizeof(z)
if GetProcessMemoryInfo(hp &z sizeof(z))
int ee = z.PagefileUsage/1024
out pid
out ee
------------------------------------------------------------------------------------------------------------------
Rob
Posts: 12,092
Threads: 142
Joined: Dec 2002
memory of current tab process
Macro
Macro366
int w=win("- Internet Explorer" "IEFrame")
int c=child("" "Internet Explorer_Server" w)
int pid; GetWindowThreadProcessId(c &pid)
out GetProcessMemoryUsage(pid)/1024.0
sum of memory of main window and all tab processes
Macro
Macro366
ARRAY(int) a
if(!ProcessNameToId("iexplore.exe" a)) ret
long mem
int i
for i 0 a.len
,mem+GetProcessMemoryUsage(a[i])
out mem/1024.0
Posts: 5
Threads: 1
Joined: Apr 2018
Nice, thx. Just had time to check the thread and see your way is way better what I came up with. Was able to accomplish the task adding in
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
g2
GetProcessExename xpid processname "iexplore.exe"
if processname = "iexplore"
pid = xpid
goto findmemory
xpid = xpid + 1
if xpid = 11000
end
goto g2
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
going through all pid names to find a match but know looping isnt ideal.
Thanks for the code, have time now to play with it. LMK if you have a donate button, really appreciate all the help.
Rob