garbage-collection

How to use IDisposable to dispose an object.

I want to use IDisposable interface to clean any resource from the memory, that is not being used. public class dispose:IDisposable { public void Dispose() { throw new NotImplementedException(); } public void fun() { PizzaFactory _pz = new PizzaFactory(); // } ...

Java GC Question: How could an object become unreachable while one of its methods is still being executed?

I have been reading these slides about Java finalizers. In it, the author describes a scenario (on slide 33) whereby CleanResource.finalize() could be run by the finalizer thread while CleanResource.doSomething() is still running on another thread. How could this happen? If doSomething() is a non-static method, then to execute that me...

Closing SqlConnection and SqlCommand c#

In my DAL I write queries like this: using(SQLConnection conn = "connection string here") { SQLCommand cmd = new ("sql query", conn); // execute it blah blah } Now it just occurred to me that I am not explicitly closing the SQLCommand object. Now I know the 'using' block will take care of the SQLConnection object, but will thi...

How to use finalize method in Objective-c?

How to call finalize method in Obj-c for garbage collection? ...

When should I be using IDisposable, is it ever wrong to use it? What about Dispose Chaining?

I'm really looking for some best practice wisdom. So here are the questions, I'll add more if people leave comments. Feel free to answer some or all of these questions. When SHOULD I use IDisposable? Only when I have unmanaged resources? What variations of the dispose pattern are there and why do they vary? What are common unmanaged ...

PHP Garbage collection sucks or is it just me?

Hello all, I have the function below which I call very frequently in a loop. I waited 5 minutes as the memory climbed up from 1MB to 156MB. Should't PHP's garabage collector turn up and reduce this at some point?! Is it because I have set memory limit at 256MB? At echo point 2,3,4 its pretty constant memory usage. It goes down my hal...

Java GC Threading Bottleneck in Practice?

How well optimized is Java's parallel collecting GC for multithreaded environments? I've written some multithreaded Jython code that spends most of its time calling Java libraries. Depending on which options I run the program with, the library calls either do tons of allocations under the hood or virtually none. When I use the options...

Calling System.gc() causing data loss in JSP

I am currently debugging a web application which has been causing intermittent problems especially when the hit rate is high. As each new user is given a session containing personalised navigation menu I thought I would try to see how much memory the session variables need. In a code section of the JSP which handles the creation of sess...

I've "fixed" a memory leak, but.. how to fix it in a better way?

It was a very fast and makeshift, bug fix.. It worked, but I would like to find a better understanding and solution. This was the Class Constructor generating the leak final transient DataInputStream din; final transient DataOutputStream dout; final transient BufferedReader bin; final transient BufferedWriter bout; NData(Socket s...

Reload Tomcat webapp automatically?

Is it possible to configure web.xml to reload a specific tomcat webapp at a particular time automatically. If not, is it possible to do this programatically? ...

What is GC collecting here?

Hi, This might be pretty basic, but was very curious to know. Here's the code snippet and the output public class PlainSystemGC { public static void main(String ...strings) { System.out.println("Free Memory (Before GC): " + Runtime.getRuntime().freeMemory()); System.gc(); System.out.println("Free Memor...

Java applet doesn't fully garbage collect on close.

I have a java applet that loads up a scroll view that you can add several thousand views to, everything works fine. If I close that browser window and open a new window and view my applet again and start adding views it eventually runs out of memory. It seems like garbage collection didn't occur when I closed the window before: a: why...

Does every user defined class needs to implement IDisposable interface to get garbage collected

I am not sure how the user defined class objects are garbage collected. Do I need to implement IDisposable interface on every class and call the dispose() method on it to free the memory? ...

How does Pythonic garbage collection with numpy array appends and deletes?

Hi all, I am trying to adapt the underlying structure of plotting code (matplotlib) that is updated on a timer to go from using Python lists for the plot data to using numpy arrays. I want to be able to lower the time step for the plot as much as possible, and since the data may get up into the thousands of points, I start to lose valua...

Sun GC maxtenuringthreshold

Hi, Have a question about Sun GC. The Sun FAQ (old one for 1.4.2) says that the throughput collector does not use the MaxTenuringThreshold (MTT) parameter. Its used only for CMS. http://java.sun.com/docs/hotspot/gc1.4.2/faq.html I dont know how to verify this, but if its true, how does the throughput collector determine when to promote...

Question about Garbage collection C# .NET

I am experiencing problem in my application with OutOfMemoryException. My application can search for words within texts. When I start a long running process search to search about 2000 different texts for about 2175 different words the application will terminate at about 50 % through with a OutOfMemoryException (after about 6 hours of pr...

How do these guys avoid creating any garbage?

Here's an interesting article that I found on the web. It talks about how this firm is able to parse a huge amount of financial data in a managed environment, essentially by object reuse and avoiding immutables such as string. They then go on and show that their program doesn't do any GC during the continuous operation phase. This is p...

Is there a way to know what keeps objects alive in C#

I'm trying to optimize memory usage of a program and therefore wants to remove objects when they aren't needed any longer. To check if this works correctly I wrote a console.writeline method in the destructor of the type of object I want to remove. However when I test the program, no lines are written (only when the program terminates of...

How is (dynamic) memory traversed by a garbage collector?

I've read about the different kinds of GC and how they work. All involve traversing the set of memory which might potentially be reclaimed, but nothing I've read gives any indication as to how this is actually done. Would something like the following be way off the mark? void* myAlloc(size_t size) { if (needToGc()) gc(); ...

Disposal Order in C# Using Blocks

I'm really bothered by having to nest using blocks in C#. It's not elegant and it takes up a lot of space. In some cases it appears to be unavoidable because I need to declare variables of different data types, but it seems like the single-type case should be possible to simplify. What I mean by "the single-type case" is when several var...