F
F
Flasher2014-11-26 09:13:19
Java
Flasher, 2014-11-26 09:13:19

Java memory leak. How to track?

There is a timer that should be constantly spinning, possibly a leak because of it (it's embarrassing that I implement it in the constructor, maybe it needs to be done differently), I can't determine the source of the leak, but the code looks something like this:

public class ClockCreater extends JPanel{
  public ClockCreater() {
    service = Executors.newSingleThreadScheduledExecutor();
    service.scheduleWithFixedDelay(new Runnable() {
      @Override
      public void run() {




      }
    }, 0, 1, TimeUnit.SECONDS);
  }
}

By the way, and the second question right away, maybe there are some applications that allow you to track a memory leak. Thank you.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
I
Ivan, 2014-11-26
@strelkov

For the second question, use Java VisualVM.

N
Nikolai Pavlov, 2014-11-26
@gurinderu

Any profiler. Either with the standard VisualVM, as mentioned above, or through jprofiler, but if you are a severe programmer, then you can also use jmap, jhat, , jstat.jstack and others (also a standard thing)

T
Trox, 2014-11-26
@Trox

on the first question:
if the ClockCreater object is created frequently, then not only memory, but also threads may leak (for example, if it is created every time a dialog box is opened). To avoid leaks, after the object is no longer needed, call shutdown on the service.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question