memory - How to destroy java objects? -


Well, I have developed a Java application using many object relationships that make memory usage very costly. I do not have any experience managing Java memory because the application design is making it difficult to destroy objects and is already using empty space. For example, I'm using more MVC patterns.

So, the principle says that ..

An object becomes eligible for garbage collection or GC if it is accessible from any live thread or any static context

In other words you can say that an object is eligible for garbage collection, if all its references are zero.

But, in my short experience, it has become very difficult for me to relate the context to those items that I want to remove from memory (for example, when a frame is closed) when you have The scenario is where you do not know how many references to your classes are present.

In this context, how can I deal with object destruction when it has many references? Or when I get complex references to each other, how do I need to manage?

keeping track

According to this reference, when the object Properties are referred to, so how can I deal with object destruction?

By making sure these references are no longer necessary.

If you separate them , even in a separate separate graph of unused objects, which are not related to your main program, then they All garbage collections are eligible for .

Local variables that have reached the end of their scope will be eligible for garbage collection (and therefore they will be included), if they have not been "linked" (added to the collection ), AC defaults, etc ...). For UI objects, in the context of object graphs that can be really difficult to reason on, make sure to settle them properly or to read the documentation, to ensure that they will be disposed naturally.

Simplified View of Reference Calculations in JVM

"Leave Alone [Gc] alone !! "

You can not "manage" the memory or when I get complex references to each other then do I need to manage memory? You can manage just references It is the idea that you do not have "serious" connection with your object in relation to your relationship. They survive in memory until GC destroyed them.

Do not try to mess with GC so that he does work. This is a very clever animal, and when you can direct request to respond to some requests - it can ignore you - it Is: Avoid the final decision and. >


Note to answer your comment

To tap a to reference only an object that has been added to several collections or composites , It does not qualify for the collection. by doing this,.

You need to remove this object from all lists or containers, in which context it is reference (basically, "forget" about this object). Once an object is still "missed" or "link" for your manufactured item, it becomes a lone object in the garbage collector's graph, which creates a candidate to remove it.

Perhaps it sounds tiring, but if you think of it with a language where you manually manage memory (C or C ++, for the names of most 2 explicit references) manually If you do, your dynamically allocated objects will actually destroy the free and zero indices, but you still want to remove the element from the list (or a container) or they like a blank bucket Will appear as individual indicator.

  • Li>
  • Here are some questions:
    • (provides a lot of additional information and links )


  • Comments