Managing Memory Usage
Freeing Memory
At times, while acquiring image data, you might want to delete
some or all of the frames that are stored in memory. Using the flushdata
function,
you can delete all the frames currently stored in memory or only those
frames associated with the execution of a trigger.
The following example illustrates how to use flushdata
to
delete all the frames in memory or one trigger's worth of frames.
Create an image acquisition object — This example creates a video input object for a Windows® image acquisition device. To run this example on your system, use the
imaqhwinfo
function to get the object constructor for your image acquisition device and substitute that syntax for the following code.vid = videoinput('winvideo',1);
Configure properties — For this example, configure an acquisition of five frames per trigger and, to show the effect of
flushdata
, configure multiple triggers using theTriggerRepeat
property.vid.FramesPerTrigger = 5 vid.TriggerRepeat = 2;
Start the image acquisition object — Call the
start
function to start the image acquisition object.start(vid)
The object executes an immediate trigger, acquires five frames of data, and repeats this trigger two more times. After logging the specified number of frames, the object stops running.
To verify that the object acquired data, view the value of the
FramesAvailable
property. This property reports how many frames are currently stored in the memory buffer.vid.FramesAvailable ans = 15
Delete a trigger's worth of image data — Call the
flushdata
function, specifying the mode'triggers'
. This deletes the frames associated with the oldest trigger.flushdata(vid,'triggers');
The following figure shows the frames acquired before and after the call to
flushdata
. Note howflushdata
deletes the frames associated with the oldest trigger.To verify that the object deleted the frames, view the value of the
FramesAvailable
property.vid.FramesAvailable ans = 10
Empty the entire memory buffer — Calling
flushdata
without specifying the mode deletes all the frames stored in memory.flushdata(vid);
To verify that the object deleted the frames, view the value of the
FramesAvailable
property.vid.FramesAvailable ans = 0
Clean up — Always remove image acquisition objects from memory, and the variables that reference them, when you no longer need them.
delete(vid) clear vid