Garbage Collection AGAIN

tehon3299

Centurion
Joined
Jan 6, 2003
Messages
155
Location
Liverpool, NY
Alright. Once again I have a question about garbage collection in .NET. I have a program that parses through a websites code and gets all the links on that page and then goes to each one of those links and gets all those links and so on. As you can imagine this program will never stop running.

BUT everytime I find a link I am creating an object of a class and after about 25 minutes I get a memory error. I have a finalize method in my class that sets the object equal to nothing but what else do I need to do to free the memory?
 
Well if its recursive, do you kill off the parent class when the child starts up? Or you could add sites to a queue and use non recursive methods.
 
You should find all the links on one page first and add them to
a list. Once they are all found, destory all objects created by that
page and then go through the list one by one doing the same thing for each page in the list.
 
Well if you're using an infinite recursive loop, then your program will never mark anything for Garbage Collection if you do the Dispose after the recursive call...

C#:
void Stuff(int i) {
   i *= 1;
   Stuff(i);
   // Some Dispose call here, but wouldn't matter.
}

In the above case you'll run out of memory eventually. A method doesn't end (and thus variables local to it will still be in memory) until it's done executing, and if it's an infinite recursive loop then your function is never done executing period.

Now that I think about it, doesn't calling a method locate memory for for that method to execute by itself? So even if you did Dispose before the recursive call you'd probably still run out of memory (it'd just take a lot longer). I might be wrong on this point though.

In any case.. infinite recursive loops are bad. :p
 
Back
Top