10-18-2010 07:42 PM
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
10-19-2010 12:03 AM - edited 10-19-2010 12:05 AM
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.
10-19-2010 09:52 AM
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
10-19-2010 10:52 AM
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
10-19-2010 08:02 PM
Thanks a lot.
David