Class Cleaner


  • public class Cleaner
    extends java.lang.Object
    Cleans up unused objects by periodically calling System.gc() to nudge the garbage collector to clean up dead native (JavaCV) objects. This is required because JavaCV objects only free their native memory when they're garbage collected, so if they accumulate in the heap, the app will use about 40x the memory as used heap (i.e. 230MB of used heap results in about 9.8GB of used memory for the process). This is because Mats and anything else extending Pointer use native memory that greatly exceeds the Java objects size on the heap.

    JavaCV has a system property org.bytedeco.javacpp.maxphysicalbytes that it uses to determine when to start deallocating native memory. However, this only results in calls to System.gc() and imposes a hard upper limit on native memory use, limiting large images or long pipelines. It's also not very portable: running from source needs it to be passed as a JVM argument with gradle, and it can't be adjusted based on the amount of memory on the system it's installed on. For us, manually running System.gc() periodically is a better solution.

    • Constructor Summary

      Constructors 
      Constructor Description
      Cleaner()  
    • Constructor Detail

      • Cleaner

        public Cleaner()
    • Method Detail

      • onRunFinished

        public void onRunFinished​(@Nullable
                                  RunStoppedEvent e)