FAQ Database Discussion Community


Are null and undefined equally valid for explicitly making objects unreachable?

javascript,garbage-collection
According to this answer on a related question, it's best to make an object explicitly unavailable if you want them to be garbage-collected. For all practical intents and purposes, does it matter whether that's done with a null value or an undefined value? Shortly put, will both of the below...

Know what objects got garbage collected

java,garbage-collection
when I look at the memory consumption of my java app I expierience a strange behavior: The application allocates 500 MB in ~10 Minutes and then the garbage collector frees the 500 MB. Then, 500 MB gets allocated and freed again, and again and again. There are no users on...

Why are there so many implementations of Object Pooling in Roslyn?

c#,.net,garbage-collection,roslyn
The ObjectPool is a type used in the Roslyn C# compiler to reuse frequently used objects which would normally get new'ed up and garbage collected very often. This reduces the amount and size of garbage collection operations which have to happen. The Roslyn compiler seems to have a few separate...

Timer does not get garbage collected [duplicate]

c#,timer,garbage-collection
This question already has an answer here: Timer not disposed when form is 5 answers When I open the class Cellule.cs, a timer is created, when Cellule.cs is closed, the timer still call the form. How can I dispose it effectively. This cause a problem because the form Cellules.Cs...

What's the difference between deallocating memory in c++ style or with garbage collector?

c++,garbage-collection
I usually hear that c++ is "faster" than every language with the garbage collector. I don't think this is the only reason, but I read that one point is that in c++ you can free memory in a faster way. Assuming to talk only about the way that a language...

c# Check Garbage Collection [duplicate]

c#,garbage-collection
This question already has an answer here: How can I write a unit test to determine whether an object can be garbage collected? 4 answers Is there any way to check what instances classes are collected by GC and what are not? The one option i found is by...

How to list all object in GC finalization list?

c#,garbage-collection,finalization
I have crash in my program, it is a visualizer for VS, so, it is very hard to debug it, i have tried to make dump and use WinDbg to study it, but it unsuccessful. So, now i try to put my hands on that list programmatically, but i don't...

Clear memory after some number of records passed

ruby-on-rails,ruby,garbage-collection,sidekiq
I have few m of records in db, and need to process it from time to time. However this operation takes all memory on my server. I'm running this operation using sidekiq. So while this task using all memory, my rails app becomes very slow. In general(no logic included) my...

Ruby GC module undefined method `malloc_allocated_size`

ruby,garbage-collection,nomethoderror
Trying to use GC module in Ruby 1.9.3 In repl (or script) getting this error include GC => Object GC.enable => false GC.malloc_allocations NoMethodError: undefined method `malloc_allocations' for GC:Module From the 1.9.3 GC Module docs, malloc_allocations is a public class method so why is Ruby saying that it is an...

Static variables in POJO and garbage collection of objects and classes

java,garbage-collection,static-members
I have written a base class for making request to repositories. It has a static field which is being used for some purpose in the application. public abstract class RepositoryRequest { private static String version; { version = 2.0; //Actual read is happening from some configuration file. } protected String...

What to look for when parallelized code runs faster in Visual Studio automated tests?

c#,multithreading,visual-studio-2010,visual-studio,garbage-collection
We have a C# (.NET 4.0 framework) project with Parallel.For loops that runs plenty fast in an automated test inside Visual Studio, but the same parallelized code doesn't run as expected in a standalone application, and we're trying to figure out why. The code is high-memory usage, but our workstations...

Garbage collection methods in c# application

c#,.net,memory-management,garbage-collection
I have this question : I can't understand why the second choice is the answer . I mean other methods ( KeepAlive and CancelFullGCNotification) will prevent system to call the finalizer. What are the differences between the four methods? In which cases, we have to use it? ...

JNI libraries deallocate memory upon garbage collection?

java,garbage-collection,jni,jcuda
I am using JCUDA and would like to know if the JNI objects are smart enough to deallocate when they are garbage collected? I can understand why this may not work in all situations, but I know it will work in my situation, so my followup question is: how can...

Rotating bitmap in main game loop without overloading GC in Android

java,android,bitmap,garbage-collection
What is the correct way to rotate bitmap every frame in main game loop? What I have tried: I created rotated bitmap every frame: Bitmap image, tmp; Matrix m; ... public void mainGameLoop(Canvas c){ m.reset(); m.postRotate(angle); tmp = Bitmap.createBitmap(image, 0, 0, width, height, m, true); c.drawBitmap(tmp, 50, 50, null); }...

What happens to unused return values?

java,garbage-collection,return-value
First I did look into this. I found the same question on here but in regards to C++: What happens to unused function return values? My interest is in Java (though the thread was indeed interesting). General consensus was that nothing really happens and if anything gets overridden later. Are...

Why aren't the earlier terms here being garbage-collected?

haskell,memory,garbage-collection,ghc,compiler-optimization
If I define the Kolakoski Sequence as kolakoski :: () -> [Int] kolakoski () = 1 : 2 : helper () where helper () = 2 : concat (zipWith replicate (helper ()) (cycle [1, 2])) and find the 500,000,000th term with kolakoski () !! 500000000 I find that when compiled...

GC behavior when assigning null to reference variable

java,garbage-collection
I was trying to understand the behavior of GC and I found something that interests me which I am unable to understand. Please see the code and output: public class GCTest { private static int i=0; @Override protected void finalize() throws Throwable { i++; //counting garbage collected objects } public...

Garbage Collection JMX Notifications in Java 8

java,garbage-collection
A while ago, I stumbled upon some monitoring code for garbage collections using JMX API. However, this is making Java8 angry since it is not considered API anymore. GcInfo and friends are restricted API now. Is is now discouraged to obtain GC information programmatically or is there another preferred way...

Create variable or call method few times - What's better?

c#,variables,methods,garbage-collection
Im wondering about creating new variable or calling method few times. What is better for overall performance and GC cleaning? Take a look: public static string GetValue(RegistryKey key, string value) { if (key.GetValue(value) == null) return null; string newValue = key.GetValue(value).ToString(); if (String.IsNullOrWhiteSpace(newValue)) return null; return newValue.ToLower(); } How can...

C# calling IDisposable.Dispose() vs making object null

c#,memory-leaks,garbage-collection,idisposable
Consider the following code: A. Toy Class class Toy { private string name; public string Name { get { return name; } set { name = value; } } private ToyAddon addOn; public ToyAddon AddOn { get { return addOn; } set { addOn = value; } } public void...

Scala hit GC overhead when running large external process

scala,garbage-collection
I have an external program which generate some data I need. Usually, I redirect its output to a file, then read it from my Scala application, e.g. app.exe > output.data Now, I want to integrate the process, so I did val stream = "app.exe" lineStream stream foreach { line =>...

Why does waiting too long to promote an object from the young generation result in less efficiency?

java,performance,garbage-collection,jvm
Why does waiting too long to promote an object from the young generation lead to inefficiency? One explanation I have seen said that if you wait too long to promote the young generation, it will become less sparse (i.e. the size of the live set will become larger, viewed as...

Effect of setting -XX:+PerfDisableSharedMem JVM flag to false

java,garbage-collection,jvm
I was referred to this GC pause issue; it suggests setting -XX:+PerfDisableSharedMem JVM flag to false. My question is what happens when we set this flag to false,

How often is garbage collected?

javascript,browser,garbage-collection
If I understand correctly the GC works like this: MyClass.prototype.render = function(){ var largeArray = []; for (var i = 0; i < 1000; i++) { largeArray.push({ firstName: 'John', lastName: 'Smith' }); } } When render() is called, largeArray is marked for garbage collection but not immediately collected. I am...

Javascript - free a memorized function

javascript,garbage-collection
I must say that I do not know the right terminology, so please forgive my some mistakes. What I have is a Table with rows. The last editable column of the last row in the table is enabled with a TabKey which automatically creates a new row. function enableTab() {...

Garbage Collection invalidates FileDescriptor?

android,garbage-collection,file-descriptor
I'm opening an asset using a FileDescriptor on Android. It appears that garbage collection changes the FileDescriptor's internal descriptor to -1. Attempting to use the FileDescriptor after that throws an exception. As a sanity check, I added this code to a blank project: try{ fd = getAssets().openFd("greensleeves.wav").getFileDescriptor(); }catch(IOException e) {...

G1GC Strange behavior

java,garbage-collection,g1gc
I've decided to try G1GC on my Eclipse Mars RC3 for JavaEE developers installation, but I observed a very strange behavior: As you can see it has run almost 700 FULL GCs for the lifecycle of the application, while only 30 minor GCs. Also I noticed that that the minor...

DOM nodes not garbage collected

javascript,memory-leaks,garbage-collection,google-chrome-devtools
I have a question about using Chrome's developer tools to debug memory leaks in a single-page web application. According to Google's documentation, after taking a heap snapshot you'll see red and yellow detached DOM nodes. The yellow nodes are those still being reference by JavaScript, and effectively represent the cause...

Garbage Collection and Using - Why is memory not released after `using{}` block?

c#,.net,garbage-collection,using
I've recently been some refactoring some old database access code. I have a library of hundreds of methods which look something like this public int getFoo(int id) { using(SqlConnection connection = ConnectionManager.GetConnection()) { string sql = "SELECT TOP(1) foo FROM bar WHERE [email protected]"; SqlCommand command = new SqlCommand(sql, connection); command.Parameters.AddWithValue("@id",...

No evacuation failures but still FullGC in G1GC

java,garbage-collection,g1gc
I'm tuning G1GC avoiding to occur FullGC. By following this tips http://www.infoq.com/articles/tuning-tips-G1-GC , I don't see any logs like "to-space exhausted". Java HotSpot(TM) 64-Bit Server VM (24.76-b04) for linux-amd64 JRE (1.7.0_76-b13), built on Dec 18 2014 16:58:39 by "java_re" with gcc 4.3.0 20080428 (Red Hat 4.3.0-8) Memory: 4k page, physical...

why do I have to swapCursor(null) in onLoaderReset?

java,android,garbage-collection,android-loadermanager,android-loader
Android's documentation ( https://developer.android.com/guide/components/loaders.html ) says that when I use loaders to do SQL queries, I should do swapCursor(null) in onLoaderReset method: onLoaderReset This method is called when a previously created loader is being reset, thus making its data unavailable. This callback lets you find out when the data is...

Unclear about V8 Garbage Collection

javascript,node.js,garbage-collection,v8
I am having a hard time wrapping my head around exactly what will be garbage collected in Node.js by V8 and why (or why not). I have an example below using the async.js library. I would love some insight into how V8 treats each case below (numbered from 1 to...

ruby c extension how to manage garbage collection between 2 objects

ruby,garbage-collection,ruby-c-extension
I have a C extension in which I have a main class (class A for example) created with the classical: Data_Wrap_Struct rb_define_alloc_func rb_define_private_method(mymodule, "initialize" ...) This A class have an instance method that generate B object. Those B objects can only be generated from A objects and have C data...

Manually calling System.GC.Collect() changes action of Windows Forms application

c#,.net,winforms,garbage-collection
I believed that manually calling System.GC.Collect() only effect performance or memory usage of application. But in this example, calling System.GC.Collect() changes application's action. using System; using System.Windows.Forms; public class Form1 : Form { public Form1() { this.Click += Form1_Click; } private void Form1_Click(object sender, EventArgs e) { CreateMyEventHandler()(sender, e); //System.GC.Collect();...

G1 young GC does not free memory - to-space exhausted

java,garbage-collection
I'm using G1GC, jdk 1.7 Java HotSpot(TM) 64-Bit Server VM (24.79-b02) for linux-amd64 JRE (1.7.0_79-b15), built on Apr 10 2015 11:34:48 by "java_re" with gcc 4.3.0 20080428 (Red Hat 4.3.0-8) Memory: 4k page, physical 32826020k(12590436k free), swap 33431548k(33358800k free) CommandLine flags: -XX:AutoBoxCacheMax=3000000 -XX:+DisableExplicitGC -XX:G1NewSizePercent=20 -XX:+HeapDumpOnOutOfMemoryError -XX:InitialHeapSize=10737418240 -XX:InitiatingHeapOccupancyPercent=70 -XX:MaxDirectMemorySize=1073741824 -XX:MaxGCPauseMillis=1000...

How do I terminate a task upon object deletion? c#

c#,garbage-collection,task
Consider the following class class Melody { public Melody() { Task.Factory.StartNew(()=>play_melody_in_loop()); } } play_melody_in_loop plays melody in loop and never completes. Instances of Melody can be collected by GC when they go out of scope. If it happens, I want to stop the playback. Can I avoid implementing IDisposable?...

WebSphere 7 - Can excessive Garbage Collection lead to out of memory?

java,memory-leaks,garbage-collection,websphere
Issue: Getting out of native memory exception and was wondering if excessive garbage collection can lead to this? Also any advice on GC policy or tuning would be helpful. I'm not sure if what I have warrants a change yet. Good Reference StackOverflow Question: Which GC Policy to Use Specs:...

Drop reference when only a single link to it

c#,reference,garbage-collection
I am storing a list of delegates in a dictionary, and then invoking them when required, problem is, when UI is no longer visible, the references to the delegates still exist, and when the UI shows up again, its a new instance, adds new references in addition to the old...

C# Memory Leak on on different machines

c#,memory-leaks,bitmap,garbage-collection
Background info I've developed a desktop application with Windows Form (C#) for scanning, previewing and saving images. The app behaviour while scanning is the following: Scan n images Get a Bitmap for each image and store it in a temporary file Show resized thumbnails as a preview Image memory management:...

How GC suspends/blocks the application threads

java,garbage-collection
I understand that GC gets triggered when a new object allocation fails or System.gc() is called. Every GC algorithm suggests that as a first step the GC thread will suspend all the application threads so that they won't affect the GC activity. But I would like to understand how GC...

Why JVM is designed in a way that it does not allow force Garbage Collection? [closed]

java,garbage-collection,jvm
As far as I know, we can't force for Garbage Collection in JAVA. The best we can do is to send a request by calling System.gc() or Runtime.gc(). Doing so will send request of Garbage collection to JVM but it’s not guaranteed that garbage collection will happen. So my question...

Will Application pause during minor GC in java?

java,garbage-collection
Will the whole application stop serving the requests during Minor GC execution? I am able to configure GC paramaters for my application. Can you please help me in understanding below GC log format. 2015-03-30T10:51:08.157-0400: 25.583: [GC [PSYoungGen: 1572864K->198625K(1835008K)] 1670953K->296714K(6029312K), 0.4902390 secs] [Times: user=1.56 sys=0.21, real=0.50 secs] 2015-03-30T10:51:50.081-0400: 67.507: [GC [PSYoungGen:...

How local variable usage infomation is maintained in .net clr source code

.net,garbage-collection,clr,jit
This great answer explains how GC is able to collect local variables before the method finishes executing: The jitter performs two important duties when it compiles the IL for a method into machine code. ... It also generates a table that describes how the local variables inside the method body...

Are Configuration.ConfigurationSettings.AppSettings values interned strings?

c#,string,garbage-collection,runtime
I read a lot about the behavior of strings in .Net. I knew that literal strings var s = "Hello World!" are interned per default and even if my application no longer reference it, the string will never collected by the garbage collector. What happens to strings which are read...

w3wp.exe Garbage Heap is FULL of Free object space and keeps on growing

memory-leaks,garbage-collection,heap,w3wp.exe
My IIS app (.NET 4.0, IIS7) is continually growing in memory, and eventually falls over, as if I have a memory leak. So I took a DMP while it was up around 1.7GB and cracked it open in WinDbg. The dumpheap -stat command showed that while I had a fair...

JVM ClassUnloadingWithConcurrentMark flag

java,garbage-collection,jvm,g1gc
I have a question about ClassUnloadingWithConcurrentMark flag since I didn't find any useful help anywhere. If we use G1GC is set to true by default (-XX:+ClassUnloadingWithConcurrentMark). If I use -XX:-ClassUnloadingWithConcurrentMark flag to turn off class unloading after G1 concurrent mark where is class unloading executed then (which phase)? I read...

Dispose/finalize pattern : disposing managed ressources

c#,garbage-collection,dispose,finalize
Let's imagine I have a class named Base with 3 attributes : class Base : IDisposable { private string _String; private Class1 classe1; private int foo; public void Dispose() { this.Dispose(true); GC.SuppressFinalize(this); } public virtual void Dispose(bool disposing) { if (disposing) { Console.WriteLine("Free Managed ressources"); //HOW TO FREE _String, class1...

Does allocation performance degrade on a large number of live instances when using G1?

java,performance,garbage-collection,g1gc
While moving from CMS to G1 for some of our applications, I noticed that one of them suffered from a startup time extended by factor 4. Application stop time due to GC cycles is not the cause. On comparing application behaviour, I disovered that this one carries a whopping 250...

How to delete a thread in Java

java,multithreading,garbage-collection
Here is the important part of my Server class: @SuppressWarnings("resource") ServerSocket server = new ServerSocket(8000); while (true) { Socket s = server.accept(); System.out.println("Client connected from " + s.getLocalAddress().getHostName()); Client chat = new Client(s); Thread t = new Thread(chat); t.start(); } As you can see, it creates a new Instance of...

Does /usr/bin/time include post program garbage collection for a java program?

java,linux,time,garbage-collection
I'm writing a benchmark matrix multiplication program implemented in both Java and C++. I'd like to reduce the influence of garbage collection on the Java program timings in order to match the C++ version as closely as possible. To this end, I've made the matrix arrays final static members of...

Exposing whether an application is undergoing GC via UDP

java,garbage-collection,jvm
The motivation behind this question is to see whether we can make a theoretical load balancer more efficient for edge-cases by first applying its regular strategy of nominating a particular node to route an HTTP request to (say, via a round robin strategy) and then "peeking" into the internal state...

JavaScriptCore on iOS: VM Garbage Collector not automatically emtpying

javascript,ios,swift,garbage-collection,javascriptcore
I'm working with JavaScriptCore on an iOS Swift project. I want to test my app now with XCodes internal XCTest framework. Now when I call the method that works with the JavaScriptCore class it generates a JSContext + JSVM, hands me what I need and that's it. But as I...

Why WeakReference to a WeakRef object is not garbage collected?

java,garbage-collection
While trying out some examples with WeakReferences,I just came across the below scenario. I am creating a hashmap and filled it with a weak reference on Employee object.Now I have two strong references, employee & weakReference . I have made both to null in the try block.Invoking the gc explicity,...

GC cleaning the object before calling onPictureTaken method

android,garbage-collection,picturecallback
I have developed an app that takes photos without previewing them to the user. My problem is that before carrying out the OnPictureTaken method, sometimes the GC cleans the object created by the method Camera.takePicture(). Therefore, when it happens, the App is not able to save that photo. Here is...

G1 doesn't process soft references

java,garbage-collection,g1gc,g1
Here is my simple gc test: public class Main { static class Data { public long[] l = new long[100]; } static List<SoftReference<Data>> list = new ArrayList<>(); public static void main(String[] args) { long i = 0; while (true) { list.add(new SoftReference<>(new Data())); ++i; if (i % 1000 == 0)...

How to subscribe to an event without preventing garbage collection?

c#,design-patterns,garbage-collection
Let's say AppConfiguration.Instance is a singleton. Now let's say my UI dynamically adds a button that should change it's text if the configuration is change, so my app could do: AppConfiguration.Instance.Changed += Changed_Handler; On the button's code, but I don't wanna do that because that will prevent garbage collecion of...

C# Garbage Collector Begin/End Callback [duplicate]

c#,callback,garbage-collection
This question already has an answer here: Is there an event for when garbage collection occurs in .NET? 5 answers I was just wondering if there is an overridable callback for the garbage collector begin/end in the .NET runtime/C#. I will also state that I have no intentions of...

Using “this” in a callback vs external variable and the garbage collector

javascript,garbage-collection
I just stumbled on the IndexedDB example on MDN which contains the following: function openDb() { var req = indexedDB.open(DB_NAME, DB_VERSION); req.onsuccess = function (evt) { // Better use "this" than "req" to get the result // to avoid problems with garbage collection. // db = req.result; db = this.result;...

Java 8 Metaspace - Avoid decrease

java,garbage-collection,metaspace
I've got a short question due to Metaspace in Java 8. I know that I can set an initial size with the -XX:MetaspaceSize - Parameter. But I wonder if it's possible to configure that this value will be the minimum size. My target is to prevent Full GCs due to...

Garbage collection of finished, unreferenced Timers

actionscript-3,timer,garbage-collection
So I've got a Timer something like: private var timer:Timer; public function doThingLater():void { timer = new Timer(1000, 1); var someBigThing:SomeBigThing = new SomeBigThing(); timer.addEventListener(TimerEvent.TIMER_COMPLETE, function():void { someBigThing.doThing(); timer = null; }); timer.start(); } and I need to be sure that someBigThing is garbage-collected. My google results keep telling me...

Potential causes of memory leaks in Android

java,android,memory-leaks,garbage-collection
I'm using leakcanery to find memory leaks in Android. I found and fixed all Activity leaks. (surprised to know there were so many BTW!). I also added watch refWatcher for all my Fragments. Question 1: Is there anything else that I should watch that may cause noticeable memory leak? Question...

Which has better garbage collection, MRI 2.2 or Rubinius 2.5.3

ruby,garbage-collection,rubinius
MRI 2.2 has had some big improvements with GC since 2.1, namely incremental GC and now it garbage collects symbols. One fellow fixed his memory leak simply by upgrading MRI, see this blog post We switched to Rubinius a while back, and one reason was because we thought it had...

Garbage Collector doesn't immediately collect finished thread [duplicate]

java,multithreading,memory-management,garbage-collection
This question already has an answer here: Why does java wait so long to run the garbage collector? 6 answers In short: I have a thread which is finished running, but not garbage collected. In long: See following example code: public void saveSomething() { Thread thread = new Thread(new...

What does it mean that the D garbage collector is “not guaranteed to run the destructor for all unreferenced objects”?

garbage-collection,d,destructor,finalizer
The D documentation at http://dlang.org/class.html#destructors states that "The garbage collector is not guaranteed to run the destructor for all unreferenced objects." However I am a little contused as to what this actually means. Is this saying that a GC implementation can choose to not call destructors when it collects the...

Can Java GC items iterated past?

java,garbage-collection,jvm
Let's say I have the following Java method: private static void testLoop() throws Exception { List<Integer> list = new ArrayList<>(); for (int i = 0 ; i < 100000 ; i++) list.add(i); for (Integer a : list) { Thread.sleep(10000); // Simulate lots of work. } } Question: Will the JVM...

Can I force collection for objects of certain type only?

c#,.net,com,garbage-collection,rcw
I have a problem with RCWs not being timely collected. I think of periodically force-starting garbage collection from inside code. However I'm not sure if that will have some undesired slowdown. I'm not actually interested in collecting all objects, I only need RCWs collected and they all have System.__ComObject type....

Java / Tomcat not using garbage collection

java,tomcat,memory-management,highcharts,garbage-collection
I'm developing a Java Spring - Hibernate web app that runs on Tomcat. Due to the app nature I'm experiencing memory/heap issues I never had before on other apps I developed. My app is a kind of analysis web tool that manages huge amounts of data that most times end...

Should I really implement IDisposable in this case?

c#,garbage-collection,idisposable
I'm currently using NDepend while developping a C# application. I get a violation on a rule stating that "Types with disposable instance fields must be disposable". I know you should in fact do that when you do something like this: class SomeClass : IDisposable { private Control _someControl; // implements...

WPF ViewModel GC

c#,wpf,mvvm,memory-leaks,garbage-collection
I have a ViewModel that on receiving an event from a Model, shows a dialog to the user by newing up the dialog's ViewModel and passing it to the dialog for data binding, i.e., public class MainViewModel { ... private void OnModelRaisedEvent(object sender, EventArgs e) { DialogViewModel dialogViewModel = new...

Will .Net call Dispose for me in this case?

.net,f#,garbage-collection,idisposable
For what I've read on the Internet, you should always call dispose on IDisposable objects as soon as you no longer need them. This question is about a particular case where (for me) is obvious that objects should no longer be needed and perhaps .Net may call dispose for me....

JVM is functioning very differently with same flags

java,garbage-collection,jvm,g1gc
I created test application (with Sheduler inside that runs every 20ms, there are reads/writes to DB) and deployed it on Glassfish server on two different PC. Both have same (copy from one PC to another) Glassfish (both have also latest JAVA version) server with following flags: -XX:+DisableExplicitGC, XX:MaxGCPauseMillis=200, -Xmx512m, -Xms512m,...

Windows task manager javaw.exe memory vs Java Mission Control

java,memory,garbage-collection
I'm helping develop a java application using my Windows 7 machine, which has Java 8 Update 45. I'm noticing a substantial difference in how much memory Windows Task Manager says is being used by the application (through the javaw.exe Image), and what Eclipse Memory Analyzer/Java Mission Control reports. Example: Java...

nodejs decrease v8 garbage collector memory usage

node.js,memory-management,garbage-collection,v8
I'm debugging a nodejs application with util module and while heapUsed value stays around 30-100MB, heapTotal value grows up to 1.4GB. Here is a question about similar behaviour I've read that this is the way how v8 garbage collector behaves, but the question is how to decrease the amount of...

Does GCHandle.Alloc allocate memory?

c#,garbage-collection
I am using .NET Memory Profiler from SciTech to reduce memory allocations rate of my program and cut frequency of garbage collections. Surprisingly, according to the profiler, the largest amount of allocations seems to be coming from GCHandle.Alloc calls I am doing to marshall existing .NET arrays to native OpenGL....

Why does restricting GC to 1 thread increase performance?

java,multithreading,garbage-collection
I have some simple java code that I wrote to artificially use a lot of RAM and I find that when I get the associated times when I use these flags: 1029.59 seconds .... -Xmx8g -Xms256m 696.44 seconds ..... -XX:ParallelGCThreads=1 -Xmx8g -Xms256m 247.27 seconds ..... -XX:ParallelGCThreads=1 -XX:+UseConcMarkSweepGC -Xmx8g -Xms256m Now,...

How to prevent module from deleting by garbage collector or reimport it inside __del__ method

python,garbage-collection
I wrote a wrapper class for logging module which has __del__method to delete log file at the end of the programm. My programm copy this log files into archive from other class and it is important to have no log files in working folder before next programm execution. But I...

.NET GC deleting object in use

c#,garbage-collection
I'm running into a problem where it would appear the GC thread is waking up and deleting an object while it's in use. While processfoo is running, and before it returns, it would appear fooCopy destructor fires in a separate thread. Has anyone seen a problem like this and if...

What is the best way to clear a BST for garbage collection?

java,garbage-collection,binary-search-tree
I want to clear a BST so as to take advantage of the garbage collector. So, to clear a BST, is it sufficient to set the root to null, so that I end up with a bunch of abandoned nodes with no pointers to them? Or is it better to...

Android - Javascript Interface with pointer to WebView - how to achive it without memleak

java,javascript,android,webview,garbage-collection
This is how I add JSInterface to Webview in Android app (we are inside of extended WebView Class): addJavascriptInterface(new JSInterface(this), "appBridge"); // 'this' is MyWebView that we are inside Then constructor JSInterface stores 'this' to his protected variable, because JSInterface methods need access to WebView class. But this way seems...

Can Collections.unmodifiableMap retain the original map?

java,dictionary,garbage-collection,unmodifiable
I have a piece of code below: class Util { private static final Map<String, String> MY_MAP; static { Map<String, String> tmpMap = new TreeMap<String, String>(); tmpMap.put("key1", "val1"); tmpMap.put("key2", "val2"); tmpMap.put("key3", "val3"); MY_MAP = Collections.unmodifiableMap(tmpMap); } public static String getVal(String key) { return MY_MAP.get(key); } } Can MY_MAP retain the tmpMap...

How is garbage collection triggered in JavaScript?

javascript,memory-management,garbage-collection
Consider JavaScript code below. I am creating array of let's say 4 elements and then immediately delete reference to it. When will garbage collection happen? I know it is specific to language implementation, but we have not that many JavaScript engines. Edit: it is the simplest possible case, but it...

How to keep very big elements on memory without exhausting the garbage collector?

haskell,optimization,garbage-collection,ghc
In Haskell, I created a Vector of 1000000 IntMaps. I then used Gloss to render a picture in a way that accesses random intmaps from that vector - that is, I had keep every single one of them in memory. The rendering function itself is very lightweight, so the performance...

A useful metric for determining when the JVM is about to get into memory/GC trouble

java,scala,garbage-collection,jvm
I have a scala data processing application that 95% of the time can handle the data thrown at it in memory. The remaining 5% if left unchecked doesn't usually hit OutOfMemoryError, but just gets into a cycle of major GCs that spikes the CPU, prevents background threads from executing and,...

PHP Garbage collection when nullifying

php,garbage-collection
If I were to do this: $bob = new Bob(); function AnnoyBob( Bob $bob ) { $bob = NULL; } // < A AnnoyBob( $bob ); A: Does $bob now lose its reference to the original pointer and now point to NULL thus having to get collected on the next...

How does copy collector in java manages to skip dead objects from visting?

java,garbage-collection
I am trying to understand how copy collector in java works. But it seems to be bit confusing that the advantage of copy collector is, it skips the visit to all the object that are supposed to be collected and moves live object to other half of heap. So my...

Counting total objects queued for garbage collection

c#,garbage-collection
I wanted to add a small debug UI to my OpenGL game, which will be updated frequently with various debugging options/output displays. One thing I wanted was a constant counter that shows active objects in each generation of the garbage collector. I don't want names or anything, just a total...

Finilize and GC.Collect [duplicate]

.net,garbage-collection
This question already has an answer here: Understanding Garbage Collection in .net 3 answers I try to understand, why there is different behavior. Code 1 different from Code 2 just with comment line Console.WriteLine(h.ToString());. But in this case Console.Beep(); in Code 1 executes before static void Main(string[] args) finished....

Can a call to Task.GetAwaiter().OnCompleted() fail because of garbage collection?

c#,garbage-collection,task-parallel-library
Example: var task = Task.Factory.StartNew(() => { Thread.Sleep(1000); throw new Exception("fault!"); }); task.GetAwaiter().OnCompleted(() => { if (task.IsFaulted) { Console.WriteLine(task.Exception); } }); The code above waits for task completion using a TaskAwaiter. I've seen code like this in several examples throughout the web, either with OnCompleted or with GetResult. Is it...

Memory leak in MediaPlayer

c#,multithreading,garbage-collection,threadpool
Can someone please explain why the following program runs out of memory? class Program { private static void ThreadRoutine() { System.Windows.Media.MediaPlayer player = new System.Windows.Media.MediaPlayer(); } static void Main(string[] args) { Thread aThread; int iteration = 1; while (true) { aThread = new Thread(ThreadRoutine); aThread.Start(); aThread.Join(); Console.WriteLine("Iteration: " + iteration++);...

Why remark phase is needed on concurrent GC

java,concurrency,garbage-collection
Concurrent GC needs remark phase. The role of remark phase is to mark modified objects during concurrent mark phase. But I think if we only mark the newly created objects during concurrent mark phase, there's no need to execute remark phase. remark phase is needed because of the modified objects....

How to disable BufferRecycler?

java,garbage-collection,jackson
I need to disable BufferRecycler to inspect its effect on garbage collection times. Any idea how can I achieve that ? Edit: I overrided _getBufferRecycler method of JsonFactory by returning null and used this JsonFactory instance to construct my ObjectMapper but It did not work. It seems Writer implementations could...

VB.NET Releasing Excel file after reading so it can be overwritten

vb.net,excel,datagridview,garbage-collection,oledb
I am having the same issue that many before me have had, and I have found several threads on the issue but my application of their fixes have not yielded any change. I am reading an excel file and populating a DataGridView with it. Very simply the user can modify...

JavaScript/JQuery Garbage Collection and Events

javascript,jquery,html,dom,garbage-collection
Lets say I have this JQuery code which selects and gets an element by it's ID and than puts click event to it: $( "someID" ).click( dummyCallback ); Later in the code I remove this element from the DOM by using replaceWith() or remove() functions. $( "someID" ).replaceWith( "<div>New Element</div>"...

-XX:+PrintTenuringDistribution doesn't print size per age

java,garbage-collection,jvm
I wrote simple program which infinitely addes objects into collection and I wanted to see standard output for PrintTenuringDistribution option: public static void main(String[] args) { while (true) { persons.add(new Person("jorik", "kornev")); } } As a program output I'm getting: Desired survivor size 5242880 bytes, new threshold 7 (max 15)...

delete ref to object in array javascript

javascript,garbage-collection
Let say we have the code: var players = []; function Player(){ var num = players.length; } players.push(new Player()); //player Can i delete this player from memory? For example: players.splice(0, 1); Will the garbage collector after this collect the player? Sorry for my english....

Prevent object from getting garbage collected

c#,garbage-collection
Inside a console app I have the following code: private static System.Timers.Timer TaskTimer; static void Main(string[] args) { //run each minute Func<double> getNextMinute = () => { return (DateTime.Now.RoundUp(TimeSpan.FromMinutes(1)) - DateTime.Now).TotalMilliseconds; }; TaskTimer = new System.Timers.Timer(getNextMinute()); TaskTimer.AutoReset = false; TaskTimer.Elapsed += (sender, e) => { TaskTimer.Interval = getNextMinute(); TaskTimerCallback(); };...

How is the concept of garbage collection related to non OOP languages

c++,c,garbage-collection,dynamic-memory-allocation
When using a language like C++ without any automatic garbage collector I understand that you have to use destructors to clean up after your objects. But how is the notion of "cleaning up" related to non OOP languages. What is the standard way of cleaning up structs and built in...

What causes long spin and sync times in Java?

java,garbage-collection,g1gc
In Java 8 Update 45, adding these options to the java call: -XX:+PrintGCApplicationStoppedTime -XX:+PrintSafepointStatistics -XX:PrintSafepointStatisticsCount=1 shows me statistics like these: vmop [threads: total initially_running wait_to_block] [time: spin block sync cleanup vmop] page_trap_count 3679.229: no vm operation [ 72 1 2 ] [ 6016 0 6016 0 0 ] 1 2015-05-22T11:25:27.519+0200:...

how does the mark (in mark-and-sweep) function trace out the set of objects accessible from the roots?

c++,c,garbage-collection
I'm trying to understand how the mark and sweep algorithm works practically in a piece of code. I understand that every time I malloc(), my malloc() function adds the memory address to a linked list? Then when I want to garbage collect, I call the mark() function which takes in...

Creating and returning object from function: can this avoid garbage collection?

javascript,object,scope,garbage-collection,return-by-reference
If I have a function that creates an object, do some stuff and than returns it. If it's true that objects are passed by reference, does this mean that the function that creates the object (or the function's scope chain) will not be available for garbage collection? Example code: function...