LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Questions on some Discard functions

There are some bewilderedness about those functions which using "Discard" as the prfix.

 

1, If calling the 'DiscardPanel()', excepting it can remove all panel resources, does it also remove all the bitmap, the controls  that belongs to the relevant panel from the 

    memory?

 

2, If having used the 'DiscardCtrl()' to remove a picture control, do I need recall the 'DiscardBitmap()' to clear the relevent bitmap's resource (e.g., the bitmap ID)?

3, If having used the 'DiscardBitmap()', do I need use the 'DeleteImage()' to clear the relevant bitmap data from the memory?

 

 

David 

0 Kudos
Message 1 of 5
(3,703 Views)

As far as I can understand, a bitmap in memory is independent from the same bitmap loaded in a control and must be treated properly.

 

If you load an image in a control within the UIR editor or using DisplayImageFile () command, only the UI object exists and discarding either the object or the whole panel frees all memory associated with it.

If you pass through a Bitmap ID using NewBitmap (), GetBitmapFromFile () or so, you have an object in memory that must be handled properly. Loading the bitmap in a control does not affect the memory object, more or less the same as displaying a waveform on a graph control does not affect the array of values in memory.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 5
(3,695 Views)

Roberto,

 

Assuming the picture control created by NewCtrl(), then using the GetBitmapFromFile() , SetCtrlBitmap() to display the control bitmap, before discarding the picture control, do I need to discard the image firstly?

 

 

David

0 Kudos
Message 3 of 5
(3,672 Views)

David,

 

When you call GetBitmapFromFile, you are creating a in-memory copy of your bitmap, which must eventually be disposed using DiscardBitmap. When you call SetCtrlBitmap, CVI duplicates your bitmap and the picture control retains a copy for itself. As Roberto explained, you don't have to worry about this copy, since it will be discarded when the picture control itself is discarded.

 

It doesn't really matter whether you discard the bitmap first or you discard the panel/control first. Personally, if it were up to me, unless you're planning on reusing this bitmap, I would discard it right after I call SetCtrlBitmap. It's good to limit the lifetime and scope of your objects to be no greater than it needs to be.

 

Luis

0 Kudos
Message 4 of 5
(3,662 Views)

Thanks a lot.

 

 

David

0 Kudos
Message 5 of 5
(3,644 Views)