Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all!

I've this problem

I've made a class that reads all emails of an account and delete spam.

The problem is that when it seems that the class isn't unloaded until I quit the program.

 

I've a While where I create n class, 1 class for every account I want to scan.

The while contains:

While (reader.Read())
Dim MyAccount As New clsPOP3
MyAccount.POP3Server = reader("server").ToString
'cut
MyAccount.Connect()
MyAccount = Nothing
End While

 

Well.. if I scan 100 times the Memory usage continues increases and newer lower..

the line

MyAccount = Nothing

is executed while MyAccount is scanning email..

Is it possible to unload an object directly By itself (something like me.unload / me = nothing)?

So i would unload my class directly from itself.

Thank u all!

See u! :cool:

  • Administrators
Posted

How long is your application running for? If it is only executing a short while then you will see this memory increase.

Under .Net memory is reclaimed through 'Garbage Collection' and the .Net implementation is lazy by design, it will only attempt to free up memory when it believes there is a benefit in doing so. As a consequence this means it behaves in a non-deterministic way i.e. there are no guarantees as to when objects will be released from memory - only that they will eventually be freed up.

The more RAM you have then you will probably notice the objects hanging around longer.

As to unloading an object from itself - as far as I'm aware this isn't possible. If your object holds on to expensive resources (network socket for example) then you may want to investigate the IDisposable interface.

If you feel you need to look into managing your resources more then have a look here

Also a nice little tool from sysinternals can be found here with this you can see how much memory is in use, amount of time spent in garbage collector etc.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Administrators
Posted
You should find that if it runs 24/7 it will reach it's own level of memory consumption. I would still carry on setting variables to nothing when I've finished, implement IDisposable if my class encapsulates a limited resource - but if it can run happily without crashing then I'd let the GC get on with it.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • *Experts*
Posted

Also something to check: I see you use a "Connect()" call but no similar "Disconnect()". Generally things like Files, connections, etc. need to have an explicit "Close" or "Disconnect" method to free the resources manually.

 

This would be in addition to using the Disposable pattern to do manual cleanup, if it's required.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

thx ;)

anyway the connect method is simply a sub that check all new emails and then close the socket.

I've rename now in Scan.. better :P

I've used the dispose method and it seems that so memory is cleared ;)

Have to make some more tests but I think that now it's all ok

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