I was observing unexpected behaviour on a program I am writing and discovered that the DestroyFcn callback is ignored half the time a block is deleted. DestroyFcn is supposed to be called after a block is graphically deleted, when the block is destroyed in the memory.
The block in quesiton is a masked subsystem in a reference model. When the block is used in a project, it's dragged from the referenced model to the project model.
I did the following investigation to identify DestroyFcn as the problem :
- Put the following code in the reference block DestroyFcn callback (contextual menu -> properties -> callback -> DestroyFcn);
2. Drag the block in a project model named 'MODEL'. Name the block 'BLOCK';
3. Run the following code to get the block Handle;
4. Delete the block, expected msgbox pop-up, but nothing happens;
5. Re run step 3 code to see if block is still loaded in memory, receive this message;
" Invalid Simulink object name: TEST/BLOCK.
No block called 'TEST/BLOCK' could be found. "
This confirms the block was deleted from memory, and the fact that no msgbox pop-up was received makes me belive that code in the callback was somehow ignored.
I also tried different lines of codes in step one such as "disp('destroy')" and different ways to test if the block is still loaded such as "getSimulinkBlockHandle".
Did anyone ever exepirenced this ? Is this a bug or am I ignorant ? I'm on 2020b.