Advertisement
Guest User

Untitled

a guest
Apr 24th, 2021
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. private Random random = new Random();
  2. public static final ArrayList<Double> list = new ArrayList<Double>(1000000);
  3.  
  4. @Test
  5. public void givenStaticField_whenLotsOfOperations_thenMemoryLeak() throws InterruptedException {
  6.    // We will only use list in this method.
  7.     for (int i = 0; i < 1000000; i++) {
  8.         list.add(random.nextDouble());
  9.     }
  10.    
  11.     System.gc();
  12.     Thread.sleep(10000); // to allow GC do its job
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement