Store values in library

Thomas, it seems like you understand the concept of classes pretty well. (Unless that's an example you copied from a textbook without understanding.)

What is stopping you from doing what you originally planned?

The example of rectangle.clearMemory() is a little contrived. For a small object like rectangle, you would create and destroy the whole object if you wanted to recover the memory. For example, make it a local variable in a function then it will be removed from memory (and all values lost) after the function ends. For a bigger class that needs to manage its own memory - maybe it needs to store a buffer with a lot of data - then malloc() and free() can be used inside the class. A better idea would be to have the variable-size memory composed of classes too and then the main class can create and destroy the data elements as it needs.