What's new
  • Visit Rebornbuddy
  • Visit Resources
  • Visit API Documentation
  • Visit Downloads
  • Visit Portal
  • Visit Panda Profiles
  • Visit LLamamMagic

Clean up memory?!

Blackclon

New Member
Joined
Sep 24, 2014
Messages
35
Reaction score
0
Hey fellow coders :)

This might be a dumb question ...
how do i free memory?

In particular my problem is:

AuctionRequestParams req = new AuctionRequestParams()

Initializes a new instance of the AuctionRequestParams class (right?)
but how do i delete this instance after done using it?

Second and more generally:
Wht stuff should be in "public void PluginStop()" i guess its called when i stop the plugin but wht would be good to do in there?
 
You don't. Unless class implements "IDisposable" you don't care about freeing memory - it gets done automagically by garbage collector when the references are removed (not immediately, but trust me, you don't need to care about it..).

When class implements "IDisposable" you should call method "Dispose" or use "using" language construct to tell the object you are done with it. This typically immediately frees native resources.

Example:
Code:
using (var fs = new MemoryStream())
{
    // do stuff
}

which is more or less equivalent to

Code:
var fs = new MemoryStream();
try
{
    // do stuff
}
finally
{
    fs.Dispose();
}


As for PluginStop (this is what I'm doing, it may be wrong, I need to verify whether the "PluginRun" thread doesn't get interrupted before calling "PluginStop"..)

- you should notify the "PluginRun" thread that you are stopping (but note that PluginStop get's called also when PluginRun ends by itself!)
- wait for "PluginRun" to react to it
- cleanup resources (call dispose on "IDisposable", possibly remove references to large managed structures..)


From what I've seen around here, you could also just ignore PluginStop if you don't need to perform clean shutdown.
 
Last edited:
Back
Top