I am reviewing one java code base for finding some memory leaks. During the review I have find the following scenarios.
- A class Class1 has in the codebase. Class1 have some instance variables and some static members. Some other classes creating the instances of the Class1. Is this scenario leads to any memory leak?
- A class Class2 available in the codebase. It have some public static inner classes. And the instance of the static inner classes is creating from the other static inner classes. Does it lead to memory leak? For example,
Class2 { public static class Class3 { } public static class Class4 { } public static class Class3 { Class3 c = new Class3(); //…. } public static int doSomething1{ } public static void doSomething2{ } public void doSomething3{ } }
Can somebody give answers?
Creating instances of other classes doesn't in itself create memory leaks.
Holding on to references longer than needed creates memory leaks.
Those references can be explicit or implicit. For example: if you create an instance of a non-static inner class then it will keep a reference to the outer instance, even if no explicit reference to that exists.
So the answer to your direct question is a definite: maybe. You need to give us more information.
And: a pretty good tool to find memory leaks is using a profiler. Especially if it's a big memory leak.