04-28-2016 10:12 AM
Hello all. I've got two deployed applications, both compiled under CVI 2015. These apps have been running for over 1 year, pretty stable. Every once in a while, I see some mysterious crashes, but rarely.
So yesterday I saw one of these crashes and decided to investigate more. Turns out that one of the apps was consuming 900MB of memory! It climbed to 1.3GB when I let Windows force close it.
Now the other application I mentioned above seems to be consuming this much memory as well. These two apps share maybe 2% of their codebases: merely some logging, error handling libraries, general UI elements. They have radically different requirements and core functionality.
And yet both, in steady state, after maybe 96 hours of continuous operation, are chewing up nearly 1GB of memory!
So there's clearly a memory leak here somewhere. I ran the execution profiler but didn't see any big issues.
Are there any known issues with the 2015 runtime?
Any hints as to what I can look at for memory cleanup / optimization?
Solved! Go to Solution.
04-29-2016 07:50 AM
There are many ways to look for memory leaks. Main one is to use Valgrind, but I'm not sure if it runs on Windows. A simpler alternative is to use a special malloc/free library that logs the calls into a file for later analysis. I've used one of those with CVI in the past.
05-01-2016 09:50 AM
Is the execution profiler the correct tool for this? Wouldn't the resource tracker be the better tool to use?
Are you using any add-on libraries/tool kits? I have run into this problem with the CVI Vision library, many functions will cause memory to be allocated, and you have to remember to call the correct function to free it. But there is no notification to the CVI resource tracking tool, all that happens is that memory gets chewed up, and you cannot see what is causing the leak.
05-02-2016 12:56 AM
Some years ago I successfully used LeakDiag software to discover and fix a memory leak in my CVI application.
I followed the suggestion described here
05-03-2016 09:27 AM
Unfortunately, I can't find LeakDiag anywhere. Microsoft must have shut down their public FTP.
I found a page for a tool called Visual Leak Detector, but it appears to be a plugin for Visual Studio Debugger.
I did a survey of my two projects and both do have one thing in common: a good number of dangling malloc calls. Uh-oh!
Both also use quite a few of the CVI libraries, like toolbox, RS232, TCP, etc.
05-03-2016 09:29 AM
I downloaded it some months ago and I can share (if it is allowed by the license and if I find a way).
05-03-2016 09:36 AM
Yes please! I think you can simply upload it here. Attachments button in the Reply dialog. Probably have to zip it first.
05-03-2016 09:39 AM
I hope than you can download the attachment
05-03-2016 09:53 AM
Bummer, I get an error during install on my 64bit PC.
The files all seem to be installed though and the EXE does indeed open. However, I'm unable to CTRL click different memory allocators and the Log button doesn't depress.
Oh well. The old-fashioned way, I suppose.
I really am beginning to suspect my usage of malloc so much inside functions without freeing elsewhere. As I understand now, these are literal strings that just go on existing for the duration of the run time.
05-04-2016 01:33 AM
Electro,
Why don't you use CVI's resource tracking?
https://decibel.ni.com/content/docs/DOC-45564
If it's malloc without free, resource tracker will point out where they are.