garbage-collection

Java Concurrency: Is cancelling Futures necessary for them to be Garbage Collected?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 11:18:59
问题 I am writing some code where I might need to create an unbounded number of future objects (java.util.concurrent.Future). But I am worried about running out of memory at some point. Couple of questions here: Does the jvm know that once the future has completed, it is not being refernced anywhere and therefore is eligible for GC (even if the thread within which it was created is still alive and running)? Ideally, I wouldn't want to keep track of these futures themselves. But if I do keep the

How to find which objects are creating the most garbage

橙三吉。 提交于 2019-12-22 10:44:19
问题 I have an application with about 80 instances of 80 different classes. The amount of garbage generated by some subset of these classes is unacceptable and stop the world pauses are too long, since my application is real time. What I want to find is which classes are responsible for creating the largest number of objects on heap (not aggregate size, but raw number of objects), since this is what causes stop the world pauses to take so long. How do I find this out? If JVisualVM is required, I

Memory release with IDisposable and without IDisposable

雨燕双飞 提交于 2019-12-22 10:42:41
问题 In my app I have a large object that's created every few seconds. I do with it some job and then I don't need it anymore. I saw in the task manager that the ram size goes up even if I don't have any reference to the object and it needs to be collected. After implementing IDisposable the ram goes down immediately. Why is this? I didn't do GC.Collect , I just released the object and told the GC it doesn't need to call the finalizer for my object. EDIT: Here is the code I use for my IDisposable

How to implement a write cache that swaps data to disk only when free memory is low

会有一股神秘感。 提交于 2019-12-22 10:38:25
问题 I want to cache data produced by my application in memory, but if memory becomes scarce I would like to swap the data to disk. Ideally I would want to be notified by the VM that it needs memory and write my data to disk and free some memory that way. But I don't see any way to hook myself into the VM in a manner that notifies me before an OutOfMemoryError occurs somewhere (most likely in code not related to the cache in any way). The Reference classes in java.lang.ref do not seem to be of any

How String object is garbage collected in java? [duplicate]

自作多情 提交于 2019-12-22 10:35:10
问题 This question already has answers here : How many String objects will be created (3 answers) Closed 2 years ago . As we know when ever we are creating String object like String value = new String("ABC"); then new String object will be created and when we use value variable again as value="xyz" then a new String object will be created. So my question is that at which point previously created String object will be garbage collected? 回答1: Whenever you call new in JAVA it create an object in heap

Java: do I need to protect a Thread object from the Garbage Collector?

血红的双手。 提交于 2019-12-22 10:31:34
问题 After { Thread t = new Thread(); t.start(); } is the Thread object a candidate for the GC? 回答1: If it's started, it's not eligible for GC - the code that's running can ask for Thread.currentThread() , after all. If you just created it but didn't start it, like this: { Thread pointless = new Thread(); } then I suspect it would be eligible for GC - but it's pretty unusual to create a thread without starting it. (I guess an exception could be thrown before you got round to starting it...) 回答2:

Does a list_iterator garbage collect its consumed values?

给你一囗甜甜゛ 提交于 2019-12-22 10:27:46
问题 Suppose I have li = iter([1,2,3,4]) . Will the garbage collector drop the references to inaccessible element when I do next(li) . And what about deque , will elements in di = iter(deque([1,2,3,4])) be collectable once consumed. If not, does a native data structure in Python implement such behaviour. 回答1: https://github.com/python/cpython/blob/bb86bf4c4eaa30b1f5192dab9f389ce0bb61114d/Objects/iterobject.c A reference to the list is held until you iterate to the end of the sequence. You can see

When is this scope/closure being garbage collected in javaScript?

橙三吉。 提交于 2019-12-22 10:24:00
问题 I am doing a course which is going through scope/closures and briefly mentions garbage collection. During the course a question is posed: How long does the scope stay around? And the answer was—until there's no longer any references to it. Yep, so what we basically said was, a closure is kind of like a reference to a hidden scope object. So as long as there's some function that still has a closure over the scope, that scope's going to stay around. But as soon as that closure goes away, scope

Garbage collection of objects referenced by static variables

。_饼干妹妹 提交于 2019-12-22 10:20:03
问题 class StaticTest{ public static SomeClass statVar = new SomeClass(); } After this if we access StaticTest.statVar and assign some new objects at random times, then when all these objects will get garbage collected? Answer: In normal garbage collection time. But what if this statVar has references to some instance variables(objects)? Not clear? Ok, static variables life time is until the class unloaded. In web applications we are initializing many things in static context. Incase if we are

ListView with getView() Over-Ridden Slow Due To Constant GC?

人盡茶涼 提交于 2019-12-22 09:54:57
问题 I have a ListView in my app, and I've over-ridden the getView() method so I can change the row's ImageView src depending on the row's text. The problem is, I've noticed the ListView scrolling is lagging, and when I check DDMS, it seems the Garbage Collector is being called everytime the ListView is being scrolled, thus slowing the scrolling. I've also noticed the Garbage Collector being called in a different part of my app, when reading lines from a BufferedReader, which makes opening a 2,000