Java: Are temporary garbage collected?

My program showed memory leak trends. When memory usage peaked, the GC counter was larger and objects were garbage collected.

We found that the class that caused the memory leak trend.

But I would like to check why the class was actually garbage collected, and when I explored the class, there was only one transition object in the class.

Adapter objects are objects that are not serialized. But does temporary nature have anything to do with garbage collection?

+4
source share
5 answers

There is no such thing as a transition object. There are temporary fields that are ignored during serialization, but this does not affect garbage collection.

Basically, I think you need to look elsewhere for your leak (even if you even have a leak).

+7
source

Does the transitional nature have to do anything with the collected garbage?

There is nothing.

The transient keyword indicates that it should not be serialized, so if something means that the deserialized objects are smaller than otherwise.

We found that the class that caused the memory leak trend.

You will have a memory leak because you store such an object in the collection when you do not need it. You must make sure that the objects you save in this way are deleted when you do not need them.


Just because you save data does not mean that you have a leak. You may need this data, so you need more memory than you expected. In this case, you need to increase the maximum memory by setting the command line -Xmx or -mx .

+2
source

No, there is no relationship. Keep in mind that if the GC ultimately clears everything correctly, you do not suffer from a memory leak; This is the way the GC works. You do not have to worry about the end of the GC, and if so, you just need to configure the JVM arguments.

+1
source

The inflow does not affect garbage collection.

  • Perhaps look at objects that are used in a narrow loop, where objects have references to each other, this can slow down garbage collection.

  • Perhaps explore the use of weak Java links.

  • Perhaps look at setting up garbage collection settings. ConcurrentSweepGC can help.

  • Maybe just take a look at allocating more stack and heap.

0
source

"Objects with transients that can be collected for garbage" exist in Java, use WeakReference for objects that should be collected as soon as gc starts, and SoftReference for something that is better to save, but should be canceled if the memory runs low.

The transient keyword does not affect memory management.

0
source

All Articles