Class JMemoryBuddy

java.lang.Object
de.sandec.jmemorybuddy.JMemoryBuddy

public class JMemoryBuddy extends 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.
  • Constructor Details

    • JMemoryBuddy

      public JMemoryBuddy()
  • Method Details

    • assertCollectable

      public static void assertCollectable(WeakReference<?> weakReference)
      Checks whether the content of the WeakReference can be collected.
      Parameters:
      weakReference - The WeakReference to check.
    • checkCollectable

      public static boolean checkCollectable(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(WeakReference<Object> weakReference)
      Checks whether the content of the WeakReference cannot be collected.
      Parameters:
      weakReference - The WeakReference to check.
    • checkNotCollectable

      public static boolean checkNotCollectable(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(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 gets executed with the API to define the required memory semantic.