garbage-collection

How does Java GC call finalize() method?

我们两清 提交于 2019-12-23 18:35:27
问题 As far as I understand, GC starts with some set of initial objects (stack, static objects) and recursively traverses it building a graph of reachable objects. Then it marks the memory taken by these objects as occupied and assumes all the rest of the memory free. But what if this 'free' memory contains an object with finalize method? GC has to call it, but I don't see how it can even know about objects that aren't reachable anymore. I suppose GC can keep track of all 'finalizable' objects

Making a heap copy of a struct in D

我们两清 提交于 2019-12-23 15:37:11
问题 How can I create a garbage-collected copy of a struct that's on the stack? Coming from a C++ background, my first guess would be a copy constructor like the one below, but it doesn't seem very idiomatic for D, and I haven't seen one in any of the D projects I've taken a look at. struct Foo { immutable int bar; this(int b) { bar = b; } // A C++-style copy constructor works but doesn't seem idiomatic. this(ref const Foo f) { bar = f.bar; } } void main() { // We initialize a Foo on the stack

Is compaction really inevitable for all JVM GC implementations?

痞子三分冷 提交于 2019-12-23 15:27:10
问题 On this link it is said that: These pauses are the result of an inevitable requirement to compact the heap to free up space. Collectors use different strategies to delay these events, but compaction is inevitable for all commercial available collectors. I was under the impression that if you keep the memory footprint of your application constant then there is no need for GC compaction to occur, in other words, it will only happen if you keep adding and collecting objects. If you have a big

ConcurrentDictionary doesn't seem to mark elements for GC when they are removed

混江龙づ霸主 提交于 2019-12-23 15:10:31
问题 I was surprised to find that my app memory footprint kept growing - the longer it run, the more memory it consumed. So with some magic of windbg I pinpointed a problem to my little LRU cache based on ConcurrentDictionary . The CD has bunch of benefits that were very cool for me (one of which is that its data never ends up in LOH). TryAdd and TryRemove are two methods used to add and evict items. !gcroot of some older element lead me back to my cache. Some investigation with ILSpy led me to

How much GCHandle pinned memory/objects would make Garbage Collector slows down?

假如想象 提交于 2019-12-23 15:09:55
问题 I'm sure this answer will depends the user machine, but there must be some best practices on pinning data . I need to hold like 5 arrays of bytes containing 1.048.576 bytes each. Normally I would prefer to use GCHandle (managed) memory, but some people says it would slow down the GC. I know that can happen, but how much memory/objects need to be pinned to start to really affect the GC? Here are the options that I have: GCHandle.Alloc GCHandleType.Pinned (managed). It will slow down GC??

Can JIT do this field access optimization?

梦想与她 提交于 2019-12-23 13:32:30
问题 Disclaimer: Please no advice concerning premature optimization. I'm just curious. Imagine I want to make sure that some objects referenced by a field can be garbage collected ASAP. I'm using a home-made singly linked list like this class BigData { byte[] someBigArray; BigData next; } private BigData bigData; and iterate like this while (bigData != null) { process(bigData); bigData = bigData.next; } Is the JIT free to change it like follows? BigData tmp = bigData; while (tmp != null) { process

Can JIT do this field access optimization?

一世执手 提交于 2019-12-23 13:32:18
问题 Disclaimer: Please no advice concerning premature optimization. I'm just curious. Imagine I want to make sure that some objects referenced by a field can be garbage collected ASAP. I'm using a home-made singly linked list like this class BigData { byte[] someBigArray; BigData next; } private BigData bigData; and iterate like this while (bigData != null) { process(bigData); bigData = bigData.next; } Is the JIT free to change it like follows? BigData tmp = bigData; while (tmp != null) { process

Memory allocation for local String literals?

冷暖自知 提交于 2019-12-23 13:25:17
问题 I know that when we create string literal, it goes inside permgenspace. My question is will it lie there for the life time of jvm even if that string literal is local to method. For example i have below code snippet:- private static void testString1(){ String str1="tetingLiteral"; } private static void testString2(){ String str2="tetingLiteral"; } now from main method i call testString1(); testString12(); will str1 and str2 will refer to same memory location. My understanding is They will

Possibility of unhandled memory leak

北慕城南 提交于 2019-12-23 13:25:09
问题 First of all, I come from iOS environment, so this is why this question might be obvious. I know Android has Garbage Collector, but objects still reference (retain) other objects, and my understanding is the GC will only remove an object if it has no references (probably I'm wrong in this point). Looking at this code: private void addDefaultTextWatcher(final EditText editText) { editText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int

Memory allocation for local String literals?

≯℡__Kan透↙ 提交于 2019-12-23 13:24:59
问题 I know that when we create string literal, it goes inside permgenspace. My question is will it lie there for the life time of jvm even if that string literal is local to method. For example i have below code snippet:- private static void testString1(){ String str1="tetingLiteral"; } private static void testString2(){ String str2="tetingLiteral"; } now from main method i call testString1(); testString12(); will str1 and str2 will refer to same memory location. My understanding is They will