How and when does processing delete objects

In processing the word new initializes a new instance of an object, for instance

Cat myCat = new Cat()

Means make a new object, from the class Cat, which can be accesed by the name myCat.

Making a new object of the class Cat, means allocating memory to store all the variables in the class Cat, the location of this data, (its adress) is then stored at the variable myCat. At some point, the object cat, won't be used anymore (at the latest when the program is terminated), then the allocated memory must be freed, but you can't write in the code when, and how you want to do that.

In the programming language C++ , you will have to use the keyword delete (or delete[]) to delete each of the objects you initialized using new. In C++ you also get to make a destructer-function when you make a class.

In processing you can't delete objects manually, so i asume, it happens automatically, but i would like to know how it works. And what about objects stored in other objects, or if more objects of the same or different class, are storring the same other object in them?

and are there a way to manually delete objects?

Answers

Sign In or Register to comment.