Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

Thanks,

Tehon

Posted
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.

Phil Price�

Visual Studio .NET 2003 Enterprise Edition

Microsoft Student Partner 2004

Microsoft Redmond, EMEA Intern 2004

  • *Experts*
Posted

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.

Posted

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

Gamer extraordinaire. Programmer wannabe.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...