Memory management

Memory management is one of the most misunderstood concepts and a source of concerns for LabVIEW™ developers.

This section gathers examples to understand when memory is allocated and deallocated.

Basic behavior

In this example, we placed breakpoints at strategic points to see how the memory allocation changes as the code runs.

Example code: 03a - Memory Management.vi

12 memory management a fp
Figure 1. Front Panel
13 memory management a dg
Figure 2. Diagram

The video below shows you the code in execution with the evolution of the memory.

Here are the key points to remember:

  1. User Events generated before the User Event is registered are not kept in memory ๐Ÿ‘‰ no memory leak.

  2. User Events generated after the registration are kept in memory ๐Ÿ‘‰ you should be very careful binding your Registred Events ref to an Event Structure

  3. When event are consumed by the Event Structure the memory is deallocated ๐Ÿ‘‰ to prevent memory issues in your code, you must ensure that Event Structure is capable of consuming all generated events it is handling.

  4. Events not consumed by the Event Structure are deallocated when calling the Unregister For Events function ๐Ÿ‘‰ always call this function when you exit an Event Structure.