Class JMemoryBuddy


  • public class JMemoryBuddy
    extends java.lang.Object
    JMemoryBuddy provides various methods to test for memory leaks. It makes it easy to verify the memory behavior in a unit test ensuring the stability and quality of your code. Checkout https://github.com/Sandec/JMemoryBuddy for more documentation.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static interface  JMemoryBuddy.MemoryTestAPI
      This class provides different methods, which can be used to declare memory-constraints.
    • Constructor Summary

      Constructors 
      Constructor Description
      JMemoryBuddy()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertCollectable​(java.lang.ref.WeakReference weakReference)
      Checks whether the content of the WeakReference can be collected.
      static void assertNotCollectable​(java.lang.ref.WeakReference weakReference)
      Checks whether the content of the WeakReference cannot be collected.
      static boolean checkCollectable​(java.lang.ref.WeakReference weakReference)
      Checks whether the content of the WeakReference can be collected.
      static boolean checkNotCollectable​(java.lang.ref.WeakReference weakReference)
      Checks whether the content of the WeakReference cannot be collected.
      static void memoryTest​(java.util.function.Consumer<JMemoryBuddy.MemoryTestAPI> f)
      A standard method to define a test which checks code for specific memory semantic.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • JMemoryBuddy

        public JMemoryBuddy()
    • Method Detail

      • assertCollectable

        public static void assertCollectable​(java.lang.ref.WeakReference weakReference)
        Checks whether the content of the WeakReference can be collected.
        Parameters:
        weakReference - The WeakReference to check.
      • checkCollectable

        public static boolean checkCollectable​(java.lang.ref.WeakReference weakReference)
        Checks whether the content of the WeakReference can be collected.
        Parameters:
        weakReference - The WeakReference to check.
        Returns:
        Returns true, when the provided WeakReference can be collected.
      • assertNotCollectable

        public static void assertNotCollectable​(java.lang.ref.WeakReference weakReference)
        Checks whether the content of the WeakReference cannot be collected.
        Parameters:
        weakReference - The WeakReference to check.
      • checkNotCollectable

        public static boolean checkNotCollectable​(java.lang.ref.WeakReference weakReference)
        Checks whether the content of the WeakReference cannot be collected.
        Parameters:
        weakReference - The WeakReference to check.
        Returns:
        Returns true, when the provided WeakReference cannot be collected.
      • memoryTest

        public static void memoryTest​(java.util.function.Consumer<JMemoryBuddy.MemoryTestAPI> f)
        A standard method to define a test which checks code for specific memory semantic. The parameter of the lambda provides an API to define the required memory semantic.
        Parameters:
        f - A function which get's executed with the API to define the required memory semantic.