How do you control of the memory is released? You can control this on the level of the operating system only.
Removing the field in the handles struct and overwriting the struct in the figure's application data by guidata removes the field efficiently. Afterwards the memory is not occupied anymore, but neither Matlab nor the OS have to give this memory back directly for allocating new arrays. Matlab can keep this memory until it finds time for a garbage collection and the OS will wait with clearing the memory by overwriting it with zeros until one of the processor cores finds the time for this job. Therefore I doubt that you can really determine when the release of the memory exactly happens.
Usually this is not a problem, because the OS cares for cleaning memory with a high precedence if it is getting low on it. Therefore the memory management is usually not a specific problem for users. What exactly is your problem you want to solve?
Best Answer