Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 3
How to free memory in java programming ?
i want to free the space used so there is any keyword or any thing I can do help me
3 Answers
+ 5
Java uses managed memory, so the only way you can allocate memory is by using the new operator, and the only way you can deallocate memory is by relying on the garbage collector.
or you can also read this article
https://stackoverflow.com/questions/1567979/how-to-free-memory-in-java?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
+ 8
Yep, usually relying on the garbage collector to do its job as Shudarshan Rai 👑 stated
To help it do its job you can use variables with limited scopes (no "globals" or long living variables you dont need (static) [Java doesnt necessarily have globals])
also setting things to null helps ;)
If your program is badly taking up resources, you can hint a garbage collection by System.gc() but ONLY if your program is bad (NetBeans has this).
+ 2
thanks you guys !
you guys are awesome