Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [garbage-collection]

The tag has no usage guidance, but it has a tag wiki.

0
votes
0answers
29 views

How to release collectiable assembly (cannot null belonging type)?

The documentation states You must release all objects that represent parts of the assembly. The ModuleBuilder that defines T keeps a reference to the TypeBuilder, and the AssemblyBuilder ...
0
votes
1answer
155 views

Wrapping WCF client with Stream for disposing

I need to consume data from a WCF service, which pipes it through a stream. The data itself is contents of an archive file, so it needs additional logic, which I am splitting off into a separate class....
3
votes
2answers
398 views

How a Garbage Collector follows pointers to discover live objects

I have read through A tour of V8: Garbage Collection and am stuck on this part: Distinguishing pointers and data on the heap is the first problem any garbage collector needs to solve. The GC needs ...
3
votes
4answers
277 views

High Performance Garbage Collection

I am new to garbage collection but have been looking around. I have noticed that Reference Counting has a very bad reputation (PHP, Python), as well as Conservative GC (Ruby) under certain conditions. ...
77
votes
11answers
20k views

Why aren't Java objects deleted immediately after they are no longer referenced?

In Java, as soon as an object no longer has any references, it becomes eligible for deletion, but the JVM decides when the object is actually deleted. To use Objective-C terminology, all Java ...
2
votes
1answer
131 views

Mark&sweep GC with automatic freeing resources

Note: I use term "resource" in opposition to memory here, resource here is file, socket, etc. Is there a language implementation that uses M&S GC (but not necessarily only that kind ¹) that is ...
1
vote
1answer
113 views

How is the “grey list” implemented in modern garbage collectors?

In the Wikipedia article for “tracing garbage collection”, the following claim is made: ...most modern tracing garbage collectors implement some variant of the tri-color marking abstraction In ...
3
votes
1answer
266 views

Should I implement object pooling for Dalvik VMs?

This question extends from these questions: Should we avoid object creation in Java? Is object pooling a deprecated technique? Well, a JVM running on a server is well optimised, I know. Programs ...
10
votes
5answers
3k views

A reference counting pattern for memory managed languages?

Java and .NET have wonderful garbage collectors that manage memory for you, and convenient patterns for quickly releasing external objects (Closeable, IDisposable), but only if they are owned by a ...
0
votes
3answers
273 views

How often can we use garbarge collection in C# [closed]

I would like to use garbage collection several times after calling some external dlls. And I wonder how often can I do this, without causing problems to my application. I'm using the following codes ...
3
votes
2answers
198 views

How do I debug memory issues on a shared server?

I have an ASP.NET web site on a shared server. The site is mainly used to house some WCF services that are used by a desktop application. We had a problem in that the server stopped responding, and ...
2
votes
1answer
148 views

Garbage collection virtual machine

Say you have a virtual machine with the following instruction set. 0 ACC <= [S] Copy address S from memory to ACC 1 ACC => [S] Copy the value of the ACC to the memory address S. 2 ...
78
votes
6answers
13k views

How does garbage collection work in languages which are natively compiled?

After browsing several answers an Stack Overflow, it is clear that some natively compiled languages have garbage collection. But it is unclear to me how exactly this would work. I understand how ...
0
votes
2answers
415 views

Does anonymous object instantiation have advantages over static object creation in this specific case?

In a Java program which I did not made and cannot change, only write extensions for it, the design forces me to create an object which will never be garbage collected. I tested and I can do it through ...
6
votes
1answer
507 views

Low latency TCP sockets in .NET

Is it possible to optimize a .NET application running on a server version of Windows for near-zero latency TCP communication? Or will there always be unpredictable/unavoidable delays? For example, ...
1
vote
1answer
457 views

Are immutable integers also collected by the Garbage Collector, like immutable strings?

I already got the idea that string variables are immutable, so the they are copied to another place in heap every time we make a change, and since GarbageCollector has to collect them all the time, it ...
5
votes
5answers
786 views

Managed code: could GC be taken care of during compile time?

Garbage collection happens during runtime, real time, while managed code is running. In C++ however, we need to write destruct statements into the code. So we could say that GC is built into the code (...
-2
votes
3answers
1k views

Static members and finalize( )

If we have a code snippet like: public class Finalizer{ static List list = new ArrayList(); public void finalize( ){ System.out.println("hello"); } } What is so special about ...
1
vote
1answer
2k views

Explicit call to finalize() method in Java

I was reading about finalize() method that it may be invoked automatically when an object is eligible for garbage collection.Now this uncertain.But what happens if we call it explicitly.Does it ...
1
vote
0answers
187 views

finding the hidden reference causing a memory leak

Here's a pretty problem. I recently had a memory leak in a java program where one huge object was not collected, even though it "should" have been collected when the whole complex graph of objects ...
0
votes
1answer
193 views

What are the significant memory management models aside from Java (GC) and C++ (manual approach)? [closed]

There are at least two distinct memory management models: Java (we do it for you) C++ (it is your responsibility) I have two questions: (1) Is GC language specific or compiler specific? (2) Do ...
8
votes
8answers
3k views

C++ delete vs Java GC

Java garbage collection takes care of dead objects on the heap, but freezes the world sometimes. In C++ I have to call delete to dispose a created object at the end of it's life cycle. This delete ...
51
votes
8answers
19k views

What happens to garbage in C++?

Java has an automatic GC that once in a while Stops The World, but takes care of garbage on a heap. Now C/C++ applications don't have these STW freezes, their memory usage doesn't grow infinitely ...
2
votes
4answers
3k views

Readability & Performance: Is it better to allow the Java garbage collector to clear a datastructure?

I work with large HashMap's and ArrayLists. When not needing them to be in memory any longer, I use myArray.clear(); to free up the memory. When my colleague saw that line, he changed it to myArray ...
4
votes
2answers
5k views

When should I worry about freeing objects from memory in Python?

I've been reading a few different guides and tutorials, as I am interested in learning some best practices of programming. I was reading the How to be a Programmer guide, and there is a section about ...
1
vote
1answer
1k views

Make PHP sessions truly last until the browser closes, and regenerating session on page requests

We have an issue where sessions are ending after a short time, 1440 seconds according to gc_maxlifetime settings which seems consistent with the issue. The PHPSESSID says it will expire when the ...
5
votes
1answer
615 views

In SPA what happens in terms of memory and performance when user hops across all the pages?

Imagine a humongous web aplication built using Single Page Application framework such as AngularJS. With its each route it downloads a couple of HTML template files. Each of these template files ...
5
votes
6answers
2k views

Does it make sense to use the term “Space Leak” with regard to Java?

I stumbled across some posts on the main stackoverflow community about whether you can have a 'memory leak' in Java and it (maybe unsurprisingly) creates a lot of contentious debate. At some point I ...
2
votes
1answer
229 views

Why is checking weird bit errors important in garbage collectors?

Here's a rough translation of a tweet by @xharaken. "Space rays hit computers and mess up the bits in the memory" "hardware bugs mess up the bits in the memory" such things almost never happen, but ...
2
votes
1answer
235 views

In garbage collecting languages (JavaScript), can I securely overwrite data?

Realizing that garbage collection and memory management is implemented differently in different environments for sake of simplicity this question will focus on JavaScript (either V8 or Seamonkey). I ...
25
votes
2answers
2k views

How different is garbage collection in pure languages?

In a pure language like Haskell, all data is immutable and no existing data structures can be changed in any way. Additionally, many algorithms on immutable data and functional programming patterns ...
3
votes
2answers
114 views

COM - with great power comes great responsibility, but at what cost? (looking for advice on coding practices when working with COM)

What is best (or commonly accepted) practice for where to declare COM object variables (scope) and how to handle cleaning them up when using structured error handling? I just spend a whole load of ...
32
votes
8answers
19k views

Is overriding Object.finalize() really bad?

The main two arguments against overriding Object.finalize() is that: You don't get to decide when it's called. It may not get called at all. If I understand this correctly, I don't think those are ...
39
votes
3answers
30k views

How does garbage collection compare to reference counting? [duplicate]

I starting working through an online course on iOS development in the new language from Apple, Swift. The instructor made a point that raised this question in my mind. He said something to the ...
0
votes
1answer
80 views

Why is it faster to compact a portion of the managed heap than the entire heap?

I was reading this article on MSDN. In the first paragraph under the "Generations and Performance" subheading is written: First, it is faster to compact the memory for a portion of the managed ...
2
votes
1answer
1k views

Changing the Garbage Collector on your JVM [closed]

My understanding is that the JVM specification only defines the behavior of a garbage collector, but does not provide implementation details. This means it is up to the JVM implementation to build the ...
-3
votes
1answer
1k views

What should be kept in mind when writing a garbage collector? [closed]

I would like to learn the important concepts behind garbage collector design. My priority is conceptual clarity, not runtime efficiency. In particular, I would like to know: What data structures are ...
7
votes
4answers
4k views

How do you find out what resources are unmanaged?

Looking through the .NET documentation, specifically the WebRequest class, I don't see any information indicating that I should wrap an instantiation of it in a using statement. Even the provided ...
1
vote
2answers
382 views

Objects or primitives as arguments

I have come across the term "garbage disposal" and now I'm worried about using up too much memory. Apparently (correct me if I'm wrong) every time an object is created, memory is reserved for it, and ...
134
votes
10answers
22k views

When is it a good idea to force garbage collection?

So I was reading a question about forcing the C# garbage collector to run where almost every single answer is the same: you can do it, but you shouldn't - except for some very rare cases. Sadly, ...
3
votes
1answer
1k views

Does the JVM's Garbage Collector clean the entire JVM HotSpot memory (C-Heap, Java Heap and Permanent Generation space) or just Java Heap?

I know that the JVM has some JVM HotSpot memory which is further divided into three areas: Java Heap Permanent Generation Space Native Heap (C-Heap) I know that Java has automatic garbage collection ...
3
votes
2answers
1k views

Garbage collection & memory leaks on hash tables

I was reading R. Read's How to be a programmer, and I came accross something I didn't understand: ...even with garbage collection, you can fill up all memory with garbage. A classic mistake is to ...
2
votes
1answer
1k views

How does AngularJS manage scope in ng-repeats?

I have a table that has around 60 rows and 20 columns. Each cell has a directive with an isolated scope. I use 2 nested ng-repeats to generate the table (one for rows and one for columns), but I'm ...
1
vote
2answers
274 views

When should we work on GC optimization? [closed]

So, I've learnt about how GC works and how can I monitor it via VisualVM, but my question is about why we should ever perform GC optimization? In our web project (JSF/Spring/Hibernate) we haven't ...
3
votes
2answers
286 views

Do compilers attach the Garbage Collector to the final executable?

Since the Garbage Collector is part of the language implementation (not OS, etc.), does the compiler has to attach the GC to the final executable? Or is it like a dependency that has to be already ...
0
votes
2answers
797 views

Advantages of unmanaged code [closed]

tl;dr: Why would I ever choose to write/compile unmanaged1 code? Lets assume that I am starting a new project. I have decided to write in a C-like language - probably one of C, C++, C# or Java. C# ...
6
votes
1answer
283 views

Does assigning NULL in a GC'ed Environment have similar effects to using free()?

I was just writing a function (in C# in this case) that stored huge amounts of data in a local variable early on in the code, let's say at 5% of the functions code. After that point, the data in this ...
1
vote
2answers
326 views

Do GC generations have any purpose (for an application programmer) other than answer to “tricky” HRs' questions?

I'm using C# for a several years, never actually willing (until I really need to) to dig into its "deep" mechanics and to intervene in GC work, IL-compiled code and so on. My point is if you ever ...
2
votes
7answers
256 views

What if any languages treat undisposed resources as an error? [closed]

I've seen lots of code like the following example. It's in Python, but the same mistake is made in all languages with managed resources: f = open('foo.txt', 'rb') for line in f: print line That's it....
8
votes
4answers
4k views

What optimizations can be done for soft real-time code in C#?

I'm writing a soft real-time application in C#. Certain tasks, like responding to hardware requests coming in from a network, needs to be finished within a certain amount of milliseconds; however it ...