Updated MemoryLeaks article (#2184)
* Create memory-leaks module * Memory Leaks * Added str.intern() * Memory Leaks updated * Updated guest article * Memory Leaks update * Remove unused resource
This commit is contained in:
parent
3184c49da5
commit
ac8e04b651
|
@ -26,21 +26,30 @@
|
|||
//@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
//@RunWith(JUnit4.class)
|
||||
//public class MemoryLeaksTest {
|
||||
|
||||
// private Random random = new Random();
|
||||
// public static final ArrayList<Double> list = new ArrayList<Double>(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<Double> list = new ArrayList<Double>(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 = "";
|
||||
|
|
Loading…
Reference in New Issue