Objects of the handle class are not identical to pointers. When you pass an object to a function (whether it is a value class or a handle class), MATLAB does not immediately make a copy of the object. It is almost like it passes a pointer (but it is not a pointer). MATLAB has a complicated COW and tries not to copy the object unless it needs to. With a high level language of MATLAB you have to give up some of the control on memory management and hope MATLAB behaves in a reasonable manner.
I agree that MATLAB has its own way to manage memory.
I find another interesting thing that graphics functions, e.g., figure(), return a double number, named graphic handle, but not a figure object.
And I can not figure out where the figure object stored. Is it sotred in currenct workspace? A persistent variable in some functions? Or in a memory segment whose adress only MATLAB knows?
"then objects of Ptr will behave like pointers". If the behaviour you mean is that once you change a Ptr, all other variables that "point" to the same object are changed as well, then yes. Example:
x = Ptr;
y = x; % both x and y "point" to the same object
x.data = 2; % now y.data is 2 as well
But I would say that "reference" like the & in C++ comes nearer to what handle classes are ...
The handle class is the superclass for all classes that follow handle semantics. A handle is a reference to an object. If you copy an object's handle, MATLAB copies only the handle and both the original and copy refer to the same object data. If a function modifies a handle object passed as an input argument, the modification affects the original input object.
hmm, why not? When you pass an object by reference to a function, the function may change the underlying/referenced object. Of course only, as long as you don't pass a const reference ... Or do I remember entirely wrong, since my C++ programming is about 10 years ago by now ;-).