tehon3299 Posted March 28, 2003 Posted March 28, 2003 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? Quote Thanks, Tehon
philprice Posted March 30, 2003 Posted March 30, 2003 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. Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
tehon3299 Posted March 30, 2003 Author Posted March 30, 2003 Well if each time a new class is created, and when it's done being used shouldn't it automatically be flagged for garbage collection? Quote Thanks, Tehon
*Experts* Volte Posted March 30, 2003 *Experts* Posted March 30, 2003 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. Quote
wyrd Posted March 30, 2003 Posted March 30, 2003 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... 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 Quote Gamer extraordinaire. Programmer wannabe.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.