Add threadedGc() function
This commit is contained in:
parent
c9ef0d2d9a
commit
943750109c
1 changed files with 8 additions and 3 deletions
|
@ -52,13 +52,18 @@ public class Miscellaneous {
|
||||||
// Ensures garbage collection
|
// Ensures garbage collection
|
||||||
// Stolen from JLibs
|
// Stolen from JLibs
|
||||||
// https://github.com/santhosh-tekuri/jlibs/blob/e001fb7286c84f456125d1be00fc9a7e3b128881/core/src/main/java/jlibs/core/lang/RuntimeUtil.java#L148
|
// https://github.com/santhosh-tekuri/jlibs/blob/e001fb7286c84f456125d1be00fc9a7e3b128881/core/src/main/java/jlibs/core/lang/RuntimeUtil.java#L148
|
||||||
public static void gc(){
|
public static void threadedGc(){
|
||||||
|
Thread gcThread = new Thread(Miscellaneous::gc);
|
||||||
|
gcThread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void gc() {
|
||||||
ObjHolder.logger.warn(Miscellaneous.class, "Forcing garbage collection");
|
ObjHolder.logger.warn(Miscellaneous.class, "Forcing garbage collection");
|
||||||
Object obj = new Object();
|
Object obj = new Object();
|
||||||
WeakReference<Object> ref = new WeakReference<>(obj);
|
WeakReference<Object> ref = new WeakReference<>(obj);
|
||||||
obj = null;
|
obj = null;
|
||||||
while(ref.get() != null)
|
while(ref.get() != null) System.gc();
|
||||||
System.gc();
|
ObjHolder.logger.warn(Miscellaneous.class, "Garbage collector finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data type conversion
|
// Data type conversion
|
||||||
|
|
Loading…
Reference in a new issue