Q:

Matlab oop - Clearing object from memory does not call 'delete' method as expected

Context
I created two similar PrimarySettings and SecondarySettings handle classes in matlab to store settings of my own and was willing to group both of them in a bigger AllSettings class for convenience. 
All classes have a PropertyChanged event to monitor for settings modifications.
The code for all classes can be visualized from here.
Problem
When I test PrimarySettings and SecondarySettings classes to check if their are effectively calling their delete method when all instances are no longer referenced in the code I have no issue:
>> ps = PrimarySettings();
>> clear ps;
Destroying PrimarySettings. 

>> ss = secondarySettings();
>> clear ss;
Destroying SecondarySettings.

The same when I test for proper event notifications:
>> as = AllSettings();
>> as.PrimarySettings.Titi = 12;
Property 'PrimarySettings.Titi' modified.

The problem is only with the AllSettings class for which delete method is never called at all:
>> as = AllSettings();
>> clear as;
!!!!!! here delete method is not called !!!!!

The object is still in memory while it is no longer referenced. This can be tested like this:
>> clear classes
Warning: Objects of 'SecondarySettings' class exist.  Cannot clear this class or any of its superclasses. 
Warning: Objects of 'PrimarySettings' class exist.  Cannot clear this class or any of its superclasses. 
Warning: Objects of 'AllSettings' class exist.  Cannot clear this class or any of its superclasses.

Investigations
The problem seems linked to the way I am attaching the PropertyChanged event (the listener is probably still alive). 
Unfortunately I truly don't understand why. Indeed, the code for attaching to events is very similar in all the classes I created.
PrimarySettings and SecondarySettings:
for idx = 1:propCount;
    listener = addlistener(obj, meta.PropertyList(idx).Name, 'PostSet', @obj.onPropertyChanged);
    listener.Recursive = true;
end

AllSettings:
for idx = 1:propCount;                
    propName = meta.PropertyList(idx).Name;
    listener = addlistener(obj, propName, 'PostSet', @obj.onPropertyChanged);
    listener.Recursive = true;
    listener = addlistener(obj.(propName), 'PropertyChanged', @obj.onSubPropertyChanged);
    listener.Recursive = true;
 end

NB: If I comment the second listener (i.e. onSubPropertyChanged) then the AllSettings class works as expected!
Question
What's wrong with the deletion of AllSettings objects ?

A:

If you need a specific diagnosis of the issue, I'm afraid you'll need to post more code, so we can trace through what's going on exactly.
But I would expect that the issue is that one of your listeners is storing a reference to another of your objects in a way that you're not expecting, so it's not getting destroyed when you call clear.
To help you diagnose things further, note that there are two ways to create listeners:

Using addlistener, which ties the listener's lifecycle to the object that is the source of the event.
Constructing the listener directly using event.listener, where the listener exists only while it is in scope, and is not tied to the event-generating object's existence.

For more information, see the section "Ways to create listeners" in this documentation page on Events and Listeners — Syntax and Techniques.
Hope that helps!

