1

I know all the theories :

I know what is GC, when to call dispose, Finalise when it is getting called.

I would like to know, in your live project ..in which scenario have used all this.

  • I mean when the project manager/client insisted you to cleanup the memory ? When you find any errors in the programs? Kind of error messages or error logs? When your program got crashed because of unwanted memory? or any other scenarios?
tshepang
  • 12,111
  • 21
  • 91
  • 136
SmartestVEGA
  • 8,415
  • 26
  • 86
  • 139

3 Answers3

5

You should not care when and how GC is called. It is inteligent enough to know when to run and what objects to free.

You should also Dispose, either manualy or using "using" all objects, that implement IDisposable. You will then prevent many errors with un-managed resources, like files.

And if you are running out of memory, then there is something wrong with your algorithm or code itself. Manualy calling GC.Collect is heavily discuraged, especialy in production code.

Euphoric
  • 12,645
  • 1
  • 30
  • 44
1

As a rule of thumb, you need to implement IDisposable if you aggregate a disposable object, or if you hold on to an unmanaged resource. Cleanup is done differently for these two scenarios. Otherwise, keep it simple, don't litter your code with dotnetisms

Similar question here

Memory leaks cause crashed up servers. Cause and effect.

Community
  • 1
  • 1
GregC
  • 7,737
  • 2
  • 53
  • 67
  • So you are saying that in your project you implemented this by default..not any one insisted or never you got a program crash ..right? – SmartestVEGA Apr 19 '11 at 05:12
  • We actually ran out of memory space on a 32-bit process before being stickler about it, but it's a big unknown. YMMV – GregC Apr 19 '11 at 05:17
1

Ressource management is something you just havce to do. It is not 'my client insisted I free my memory'. It is simply good practice. Not all applications may crash and the user just restarts them - there is one or other server application out there.

If you start building your programming libraries, ressource management and concurrency should be your top priority, otherwise you will never be up to speed implementing any solution.

hth

Mario

Mario The Spoon
  • 4,799
  • 1
  • 24
  • 36