Questions tagged [garbage-collection]

Garbage collection (GC) is a form of automatic memory management which attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program.

1371
votes
18answers
270k views

Proper use of the IDisposable interface

I know from reading the MSDN documentation that the "primary" use of the IDisposable interface is to clean up unmanaged resources.To me, "unmanaged" means things like database connections, sockets, ...
138
votes
3answers
44k views

Understanding garbage collection in .NET

Consider the below code:public class Class1{public static int c;~Class1(){c++;}}public class Class2{public static void Main(){{var ...
597
votes
14answers
693k views

Error java.lang.OutOfMemoryError: GC overhead limit exceeded

I get this error message as I execute my JUnit tests:java.lang.OutOfMemoryError: GC overhead limit exceededI know what an OutOfMemoryError is, but what does GC overhead limit mean? How can I solve ...
676
votes
20answers
993k views

How to read a large text file line by line using Java?

I need to read a large text file of around 5-6 GB line by line using Java.How can I do this quickly?
266
votes
16answers
427k views

When is the finalize() method called in Java?

I need to know when the finalize() method is called in the JVM. I created a test class which writes into a file when the finalize() method is called by overriding it. It is not executed. Can anybody ...
279
votes
13answers
104k views

Why is it bad practice to call System.gc()?

After answering a question about how to force-free objects in Java (the guy was clearing a 1.5GB HashMap) with System.gc(), I was told it's bad practice to call System.gc() manually, but the comments ...
284
votes
8answers
111k views

What is JavaScript garbage collection?

What is JavaScript garbage collection? What's important for a web programmer to understand about JavaScript garbage collection, in order to write better code?
182
votes
21answers
263k views

How to force garbage collection in Java?

Is it possible to force garbage collection in Java, even if it is tricky to do? I know about System.gc(); and Runtime.gc(); but they only suggest to do GC. How can I force GC?
332
votes
12answers
325k views

Deleting Objects in JavaScript

I'm a bit confused with JavaScript's delete operator. Take the following piece of code:var obj={helloText: "Hello World!"};var foo=obj;delete obj;After this piece of code has been ...
130
votes
8answers
41k views

How does Java Garbage Collection work with Circular References?

From my understanding, garbage collection in Java cleans up some object if nothing else is 'pointing' to that object.My question is, what happens if we have something like this:class Node {...
101
votes
17answers
125k views

When does System.gc() do anything

I know that garbage collection is automated in Java. But I understood that if you write System.gc() in your code the Java VM may or may not decide at runtime to do a garbage collection at that point. ...
117
votes
5answers
50k views

Is explicitly closing files important?

In Python, if you either open a file without calling close(), or close the file but not using try-finally or the "with" statement, is this a problem? Or does it suffice as a coding practice to rely ...
140
votes
9answers
120k views

Stack, Static, and Heap in C++

I've searched, but I've not understood very well these three concepts. When do I have to use dynamic allocation (in the heap) and what's its real advantage? What are the problems of static and stack? ...
163
votes
4answers
22k views

Do event handlers stop garbage collection from occurring?

If I have the following code:MyClass pClass=new MyClass();pClass.MyEvent +=MyFunction;pClass=null;Will pClass be garbage collected? Or will it hang around still firing its events whenever ...
199
votes
5answers
57k views

How does the new automatic reference counting mechanism work?

Can someone briefly explain to me how ARC works? I know it's different from Garbage Collection, but I was just wondering exactly how it worked.Also, if ARC does what GC does without hindering ...
141
votes
22answers
77k views

When is it acceptable to call GC.Collect?

The general advise is that you should not call GC.Collect from your code, but what are the exceptions to this rule?I can only think of a few very specific cases where it may make sense to force a ...
78
votes
6answers
37k views

Are static fields open for garbage collection?

Given an hypothetical utility class that is used only in program setup:class MyUtils {private static MyObject myObject=new MyObject();/*package*/static boolean doStuff(Params... params) {...
486
votes
20answers
472k views

Is there a destructor for Java?

Is there a destructor for Java? I don't seem to be able to find any documentation on this. If there isn't, how can I achieve the same effect?To make my question more specific, I am writing an ...
263
votes
12answers
231k views

Do you need to dispose of objects and set them to null?

Do you need to dispose of objects and set them to null, or will the garbage collector clean them up when they go out of scope?
110
votes
15answers
141k views

Best Practice for Forcing Garbage Collection in C#

In my experience it seems that most people will tell you that it is unwise to force a garbage collection but in some cases where you are working with large objects that don't always get collected in ...
123
votes
1answer
71k views

Python garbage collector documentation [closed]

I'm looking for documents that describes in details how python garbage collection works.I'm interested what is done in which step. What objects are in these 3 collections? What kinds of objects are ...
103
votes
11answers
14k views

Understanding the meaning of the term and the concept - RAII (Resource Acquisition is Initialization)

Could you C++ developers please give us a good description of what RAII is, why it is important, and whether or not it might have any relevance to other languages?I do know a little bit. I believe ...
383
votes
8answers
304k views

Where Is Machine.Config?

I want to apply a change so That I can use Server GC settings for my C# 3.5 app - I can do that by editing the machine.config file.The only problem is I do not know where that is.How can I find ...
92
votes
20answers
53k views

What's so wrong about using GC.Collect()?

Although I do understand the serious implications of playing with this function (or at least that's what I think), I fail to see why it's becoming one of these things that respectable programmers ...
77
votes
8answers
92k views

Java 7 (JDK 7) garbage collection and documentation on G1

Java 7 has been out for a while now, but I cannot find any good resources on the configuration of the garbage collectors, specifically the new G1 collector.My questions:Is G1 the default collector ...
17
votes
4answers
12k views

Garbage collection of String literals

I am reading about Garbage collection and i am getting confusing search results when i search for String literal garbage collections.I need clarification on following points:If a string is defined ...
16
votes
2answers
2k views

finalize() called on strongly reachable object in Java 8

We recently upgraded our message processing application from Java 7 to Java 8. Since the upgrade, we get an occasional exception that a stream has been closed while it is being read from. Logging ...
88
votes
5answers
30k views

Why Large Object Heap and why do we care?

I have read about Generations and Large object heap. But I still fail to understand what is the significance (or benefit) of having Large object heap?What could have went wrong (in terms of ...
70
votes
13answers
30k views

Does assigning objects to null in Java impact garbage collection?

Does assigning an unused object reference to null in Java improve the garbage collection process in any measurable way?My experience with Java (and C#) has taught me that is often counter intuitive ...
84
votes
16answers
102k views

What is the garbage collector in Java?

I am new to Java and confused about the garbage collector in Java. What does it actually do and when does it comes into action. Please describe some of the properties of the garbage collector in Java.
23
votes
3answers
8k views

Does GC release back memory to OS?

When the garbage collector runs and releases memory does this memory go back to the OS or is it being kept as part of the process. I was under the strong impression that the memory is never actually ...
90
votes
3answers
157k views

Java Garbage Collection Log messages

I have configured java to dump garbage collection information into the logs (verbose GC). I am unsure of what the garbage collection entries in the logs mean. A sample of these entries are posted ...
99
votes
6answers
54k views

Does setting Java objects to null do anything anymore?

I was browsing some old books and found a copy of "Practical Java" by Peter Hagger. In the performance section, there is a recommendation to set object references to null when no longer needed. In ...
266
votes
8answers
187k views

Java heap terminology: young, old and permanent generations?

I'm trying to understand how the concepts of young, old and permanent generations in the Java heap terminology, and more specifically the interactions between the three generations.My questions are: ...
73
votes
4answers
27k views

Java Thread Garbage collected or not

This question was posted on some site. I didnt find right answers there, so I am posting it here again. public class TestThread {public static void main(String[] s) {// anonymous ...
27
votes
2answers
12k views

How does garbage collection work in JavaScript?

How does garbage collection work in JavaScript? Is it similar to .NET garbage collection? And is it because the implementation of garbage collection in VBScript is bad that people avoided it and ...
57
votes
5answers
23k views

What are the roots?

What are the roots in garbage collection?I have read the definition of root as "any reference that you program can access to" and definition of live is that an object that is being used, which can ...
119
votes
13answers
152k views

How to free memory in Java?

Is there a way to free memory in Java, similar to C's free() function? Or is setting the object to null and relying on GC the only option?
51
votes
7answers
44k views

Find out the size of a .net object

I'm trying to find out how much memory my objects take to see how many of them are ending up on the Large Object Heap (which is anything over 85,000 bytes).Is it as simple as adding 4 for an int, 8 ...
52
votes
2answers
23k views

Prevent .NET Garbage collection for short period of time

I have a high performance application that is handling a very large amount of data. It is receiving, analysing and discarding enormous amounts of information over very short periods of time. This ...
61
votes
4answers
8k views

Why does a System.Timers.Timer survive GC but not System.Threading.Timer?

It appears that System.Timers.Timer instances are kept alive by some mechanism, but System.Threading.Timer instances are not.Sample program, with a periodic System.Threading.Timer and auto-reset ...
39
votes
6answers
30k views

Java garbage collector - When does it collect?

What is it that determines when the garbage collector actually collects? Does it happen after a certain time or after a certain amount of memory have been used up? Or are there other factors?
230
votes
16answers
125k views

Why doesn't C++ have a garbage collector?

I'm not asking this question because of the merits of garbage collection first of all. My main reason for asking this is that I do know that Bjarne Stroustrup has said that C++ will have a garbage ...
110
votes
7answers
85k views

Implementing IDisposable correctly

In my classes I implement IDisposable as follows:public class User : IDisposable{public int id { get; protected set; }public string name { get; protected set; }public string pass { ...
41
votes
4answers
35k views

Unloading the Assembly loaded with Assembly.LoadFrom()

I need to check the time amount to run GetTypes() after loading the dll.The code is as follows.Assembly assem=Assembly.LoadFrom(file);sw=Stopwatch.StartNew();var types1=assem.GetTypes();sw....
92
votes
1answer
152k views

GC overhead limit exceeded

What is the sampling time JVM uses to throw 'java.lang.OutOfMemoryError : GC overhead limit exceeded'? I know you can control 98% and 2% with parameters GCTimeLimit and GCHeapFreeLimit but whats the ...
16
votes
4answers
15k views

In java when does an object become unreachable?

In java, what is an unreachable object? When does the object become unreachable? While studying garbage collection i was not able to understand this concept.Can anyone give any ideas with examples?
17
votes
2answers
1k views

Can java finalize an object when it is still in scope?

I've been looking into a bug in my code that seems to be caused by some "ugly" finalizer code. The code looks roughly like thispublic class A {public B b=new B();@Override public void ...
6
votes
1answer
4k views

C++ standard library and Boehm garbage collector

I want to develop a multi-threaded C++ application (where eventually most of the C++ code would become generated by the application itself, which could be viewed as a high-level domain specific ...
57
votes
6answers
24k views

Forcing garbage collection to run in R with the gc() command

Periodically I program sloppily. Ok, I program sloppily all the time, but sometimes that catches up with me in the form of out of memory errors. I start exercising a little discipline in deleting ...

153050per page
angop.ao, elkhabar.com, noa.al, afghanpaper.com, bbc.com, time.com, cdc.gov, nih.gov, xnxx.com, github.com,