diff --git a/guest/memory-leaks/src/test/java/com/baeldung/MemoryLeaksTest.java b/guest/memory-leaks/src/test/java/com/baeldung/MemoryLeaksTest.java index 13052a9487..dd99266376 100644 --- a/guest/memory-leaks/src/test/java/com/baeldung/MemoryLeaksTest.java +++ b/guest/memory-leaks/src/test/java/com/baeldung/MemoryLeaksTest.java @@ -26,21 +26,30 @@ //@FixMethodOrder(MethodSorters.NAME_ASCENDING) //@RunWith(JUnit4.class) //public class MemoryLeaksTest { - // private Random random = new Random(); // public static final ArrayList list = new ArrayList(1000000); // -// @Test(expected = OutOfMemoryError.class) +// @Test // public void givenStaticField_whenLotsOfOperations_thenMemoryLeak() throws InterruptedException { -// while (true) { -// int k = random.nextInt(100000); -// System.out.println(k); -// Thread.sleep(10000); //to allow GC do its job -// for (int i = 0; i < k; i++) { -// list.add(random.nextDouble()); -// } +// for (int i = 0; i < 1000000; i++) { +// list.add(random.nextDouble()); // } +// Thread.sleep(10000); //to allow GC do its job +// } // +// +// @Test +// public void givenNormalField_whenLotsOfOperations_thenGCWorksFine() throws InterruptedException { +// addElementsToTheList(); +// System.gc(); +// Thread.sleep(10000); //to allow GC do its job +// } +// +// private void addElementsToTheList(){ +// ArrayList list = new ArrayList(1000000); +// for (int i = 0; i < 1000000; i++) { +// list.add(random.nextDouble()); +// } // } // // @SuppressWarnings({ "resource" }) @@ -51,11 +60,11 @@ // str.intern(); // System.out.println("Done"); // } - +// // @Test(expected = OutOfMemoryError.class) // public void givenURL_whenUnclosedStream_thenOutOfMemory() throws IOException, URISyntaxException { // String str = ""; -// URLConnection conn = new URL("http://norvig.com/big.txt").openConnection(); +// URLConnection conn = new URL("http:norvig.com/big.txt").openConnection(); // BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), StandardCharsets.UTF_8)); // while (br.readLine() != null) { // str += br.readLine(); @@ -66,7 +75,7 @@ // @SuppressWarnings("unused") // @Test(expected = OutOfMemoryError.class) // public void givenConnection_whenUnclosed_thenOutOfMemory() throws IOException, URISyntaxException { -// URL url = new URL("ftp://speedtest.tele2.net"); +// URL url = new URL("ftp:speedtest.tele2.net"); // URLConnection urlc = url.openConnection(); // InputStream is = urlc.getInputStream(); // String str = ""; diff --git a/xml/src/test/resources/Customer1.xml b/xml/src/test/resources/Customer1.xml old mode 100755 new mode 100644