Mercurial > hg > Members > sugi > memoryleak
changeset 0:4dbea8e22628
Memory Leak TEST
author | e095732 |
---|---|
date | Mon, 28 Jan 2013 22:05:30 +0900 |
parents | |
children | 0a4fdcd1ed46 |
files | .classpath .project .settings/org.eclipse.core.resources.prefs .settings/org.eclipse.jdt.core.prefs src/example1/FishData.java src/example1/MemoryLeak.java src/example2/MyStack.java |
diffstat | 7 files changed, 134 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.classpath Mon Jan 28 22:05:30 2013 +0900 @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="src" path="src"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> + <classpathentry kind="output" path="bin"/> +</classpath>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.project Mon Jan 28 22:05:30 2013 +0900 @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>OS-SAMPLE</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.core.resources.prefs Mon Jan 28 22:05:30 2013 +0900 @@ -0,0 +1,2 @@ +eclipse.preferences.version=1 +encoding//src/example2/MyStack.java=UTF-8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.settings/org.eclipse.jdt.core.prefs Mon Jan 28 22:05:30 2013 +0900 @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/example1/FishData.java Mon Jan 28 22:05:30 2013 +0900 @@ -0,0 +1,21 @@ +package example1; + +import java.util.Random; + +public class FishData { + private double x; + private double y; + private double z; + + public FishData(){ + Random rnd = new Random(); + x = (double) rnd.nextInt(800); + y = (double) rnd.nextInt(800); + z = (double) rnd.nextInt(800); + } + + public double getX(){ return x;} + public double getY(){ return y;} + public double getZ(){ return z;} + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/example1/MemoryLeak.java Mon Jan 28 22:05:30 2013 +0900 @@ -0,0 +1,22 @@ +package example1; + +import java.util.LinkedList; + +public class MemoryLeak { + private LinkedList<FishData> list = new LinkedList<FishData>(); + + public static void main(String[] args){ + MemoryLeak ml = new MemoryLeak(); + LinkedList<FishData> fishlist = ml.getList(); + for (int count=0;count<Integer.MAX_VALUE;count++){ + if (count % 100000 == 0){ + System.out.println((Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024 / 1024 + "MB"); + } + fishlist.add(new FishData()); + } + } + + public LinkedList<FishData> getList(){ + return list; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/example2/MyStack.java Mon Jan 28 22:05:30 2013 +0900 @@ -0,0 +1,55 @@ +package example2; + +public class MyStack { + private Object[] stack; + private int size = 0; + private static final int MAX_SIZE = 16; + + public MyStack() { + this.stack = new Object[MAX_SIZE]; + } + + public void push(Object e) { + if (size==MAX_SIZE) return; + stack[size++] = e; + } + + public Object pop() { + if (size == 0) { + return null; + } + return stack[--size]; + } + + private void print() { + for (Object o : this.stack) { + if (o == null) { + System.out.print("n "); + } else { + System.out.print(o + " "); + } + } + System.out.println(); + } + + public static void main(String[] args) { + MyStack s = new MyStack(); + + System.out.print("First:"); + s.print(); + + for (int i = 0; i < 10; i++) { + s.push(Integer.valueOf(i)); // push + } + + System.out.print("push: "); + s.print(); + + for (int i = 0; i < 10; i++) { + s.pop(); + } + + System.out.print("pop: "); + s.print(); + } +} \ No newline at end of file