LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Bitmaps from files uses excessive memory

Solved!
Go to solution

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.

0 Kudos
Message 1 of 9
(4,889 Views)

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?

Cheers,
Kelly R.
Applications Engineer
National Instruments
0 Kudos
Message 2 of 9
(4,864 Views)

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.

0 Kudos
Message 3 of 9
(4,847 Views)

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.  

Cheers,
Kelly R.
Applications Engineer
National Instruments
0 Kudos
Message 4 of 9
(4,818 Views)

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.

0 Kudos
Message 5 of 9
(4,814 Views)

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 

0 Kudos
Message 6 of 9
(4,793 Views)

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?

0 Kudos
Message 7 of 9
(4,781 Views)
Solution
Accepted by topic author stuart_chapman

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

0 Kudos
Message 8 of 9
(4,726 Views)

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

0 Kudos
Message 9 of 9
(4,575 Views)