Your best option is to call System.gc()
which simply is a hint to the garbage collector that you want it to do a collection. There is no way to force and immediate collection though as the garbage collector is non-deterministic.
More Related Contents:
- How ‘random’ is allocation of memory when I say “new Integer” in Java?
- Error java.lang.OutOfMemoryError: GC overhead limit exceeded
- Can java finalize an object when it is still in scope?
- Does GC release back memory to OS?
- Is there a destructor for Java?
- Are static fields open for garbage collection?
- Garbage collection of String literals
- Java garbage collector – When does it collect?
- Garbage collection on a local variable
- Android – Activity Constructor vs onCreate
- Which loop has better performance? Why?
- When and how are classes garbage collected in Java?
- Size of Huge Objects directly allocated to Old Generation
- Java still uses system memory after deallocation of objects and garbage collection
- Thread Caching and Java Memory model
- Will .hashcode() return a different int due to compaction of tenure space?
- Java GC safepoint
- Calling System.gc( ) explicitly?
- Does the garbage collector work on static variables or methods in java?
- How does Java Garbage collector handle self-reference?
- Do anonymous classes *always* maintain a reference to their enclosing instance?
- In Java is Permanent Generation space garbage collected?
- How do you Force Garbage Collection from the Shell?
- When would the garbage collector erase an instance of an object that uses Singleton pattern?
- Is the garbage collector guaranteed to run before Out of Memory Error?
- Java GC (Allocation Failure)
- How to reduce java concurrent mode failure and excessive gc
- Static references are cleared–does Android unload classes at runtime if unused?
- How to read a verbose:GC output?
- What GC parameters is a JVM running with?