I know that Java have its own garbage collection, but sometimes I want to delete the garbage manually. Is there any way to do the work like that? And considering that I have a long or very long function which declares many variables, is this a good idea to delete the unused memory immediately after using instead of auto collection at the end of the function? If I delete garbage manually, does it affect the speed of my application? Thanks for helping!
I know that Java have its own garbage collection, but sometimes I want to
Share
There is no direct and immediate way to free memory in java. You might try to persuade the garbage collector to take away some object using the well known:
but there is no guarantee that this will actually free memory immediately.
While this applies to heap memory, stack allocated items can only be freed when the function returns.