System.gc() vs GC button in JVisualVM/JConsole

后端 未结 4 792
醉话见心
醉话见心 2021-02-09 17:33

I\'m currently testing my proof of concept prototype dealing with XML schema, and built around a very memory consuming external library for tree automata (for which I\'ve got th

4条回答
  •  孤街浪徒
    2021-02-09 18:19

    You can kinda force GC like this....

    private static void force_gc()
    {
        Object obj = new Object();
        WeakReference ref = new WeakReference(obj);
        obj = null;
        while (ref.get() != null)
        {
            Log.d(LOGTAG, "Forcing gc() ...");
            System.gc();
        }
    }
    
    
    

    apart from that... i'm interested to see where this question goes.

    提交回复
    热议问题