Junior — Middle
What automatic memory cleanup methods do you know?
sobes.tech AI
Answer from AI
Methods of automatic memory cleanup include:
-
Garbage Collection — automatic detection and freeing of unused objects in memory. In Java, this is implemented by the JVM, which periodically runs the garbage collector.
-
Reference Counting — objects are deleted when the number of references to them becomes zero. Used in some languages and systems.
-
Automatic Reference Counting (ARC) — used, for example, in Swift and Objective-C, where the compiler inserts calls to increase and decrease the reference count.
-
Object pools and weak references — help manage object lifetimes and prevent leaks.
In Java, the main method is garbage collection, which frees memory without the need for manual management.