12-13-2009 08:54 PM
When I load a jpg picture as a bitmap I lose a lot of memory that I am unable to recover.
I use the GetBitmapfromfile, the GetBitmapInfo, then GetBitmapData, then DiscardBitmap.
after this I have about 120 M of memory (for a 5 M pixel image) missing that I cannot recover. The size of this lost memory is proportional to the number of pixels in the image.
Solved! Go to Solution.
12-14-2009 03:05 PM
Hi Stuart,
Which version of CVI are you using? Also, how are you detecting this leak? I tried to replicate your issue in CVI 9.0.1 and I did not see the issue. Would it be possible to post a snippet of code that exhibits this behavior?
12-14-2009 11:09 PM
Hi Kelly
Thanks for your response. I am using CVI 8.1.0. I detect the memory through using windows task manager.
My real problem is that my final application is using too much memory and going into virtual memory too much, when I have been tracing my memory usage I have a lot of memory unaccounted for and I cannot get it back. This happens when I load the bitmap, and cannot be recovered untill my program is stopped.
I have attached some code with pictures to try (use the 2 DSCxxx for comparision to my run). I have also enclosed screen shots so you can see how the memory is used on my PC. Sorry for the large file size, I thought it best to send the same sample photos I have been using.
12-15-2009 02:04 PM
Hi Stuart,
Thank you for the additional information. The behavior that you are seeing is due to the way CVI manages memory. When you call the GetBitmapfromfile function, CVI allocates enough memory to create the bitmap, and the memory is released to the CVI engine when you call DiscardBitmap. CVI however does not release this newly freed memory completely, but rather it will keep it to parcel out later in your application if additional memory is required. You will still see the memory usage in Task Manager even though it has been freed from its original use in your program. You will see the drop in memory in Task Manager when the process ends.
12-15-2009 04:15 PM
Hi Kelly
Thanks for looking into this for me. This behaviour is causing me problems as I am now using up too much virtual memory which is causing my application to be slowed down too much. How can I force CVI to release that memory so I do not need to waste so much time in virtual memory.
12-16-2009 09:46 AM
Hey Stuart -
The short answer is that you can not force CVI to release this memory directly. It may happen as a side effect of some operations such as discarding a panel or control, but ultimately, it is up to the CVI memory manager. For a more technical explanation, see the responses by LuisG in this thread and this thread.
NickB
National Instruments
12-16-2009 05:39 PM
Hi Nick and Kelly
Thanks for your help, at least I understand the issues now.
Is there another way to get pictures (jpg, BMP etc) in from file without lossing / using so much memory?
12-22-2009 12:13 PM
Stuart,
There is no way to not use the initial memory. However, a possible workaround would be for you to create a new, temporary panel, using the NewPanel function, and then discard it immediately afterwards, using DiscardPanel. You don't have to display the panel. You can do this right after you discard the bitmap. I realize this is a hack, but this might result in forcing CVI to return the unused memory back to the system, and it should not affect the behavior of your program in any way.
Luis
01-12-2010 03:46 PM
Hi Luis, Nick and Kelly
Thanks for that information. I tried it and it worked well. Now I do not use so much virtual memory and slow down my application. Thanks also everone for helping me understand how the CVI engine manages memory.
Thanks
Stuart