Ok guys...3rd thread about this....
Q1: Does the variables that are declared like int x = new int(); use memory if not set to null after it's no longer used?
Q2:is there a way to delete a variable if it's no longer used?
Q3:is it of any use to set the variables/arrays/hastables etc to null after not being used anymore?
Q4:when does GC.Collect() collects the garbage (resources)?
I am using GC.Collect in a thread running every 1 second and I've also set the variables to null after their no longer used but it seems just like more and more memory is used to idk o.O
Addressing the title: you can't have a 'memory leak' in C# unless you're calling C functions. Using the FCL you won't get any.
ValueTypes (ints, doubles, shorts, etc) don't use heap memory, they use stack memory. Stack memory is cleared after the function exits.
Classes such as arrays/hashtables are managed and consume memory. You can't explicitly delete them from memory; the GC will handle it when it goes out of scope. C# is garbage collected, you don't need to worry about memory management.
It's not of any use really as the object will be cleaned up when it goes out of scope anyways.
The GC compacts and frees resources periodically when it needs to. If your program isn't tight for memory it won't bother running too frequently (as it does have to interrupt your program). You shouldn't call it explicitly as the algorithm it has on its own will be the most efficient 95% of the time.
If you really want to learn I'll give a better explanation of why later.
One of the most likely problems you have is either, as tao said, relating to the size of your hashtables and dictionary entries, so forth.
Use ANTS, or something like it, and you can find out what variables are taking up the most space, and for the most part can help you defeat them. Afaik the GC will -not- dispose of any object inside of a hashtable or collection unless the collection is disposed of.
well i believe collections are my problem...not sure tho...also I've noticed that if i put .clear instead of = null; to a collection after I don't need it anymore it doesn't free any memory at all...
Well hybrids videos are awesome, they explain alot and what could cause problems and so and he tells alot about collections wich I really like.
Its awesome.
Also he explains why u get alot random null exceptions.
Wich is awesome
well i believe collections are my problem...not sure tho...also I've noticed that if i put .clear instead of = null; to a collection after I don't need it anymore it doesn't free any memory at all...
If you clear a collection, it removes the objects from the collection, allowing the GC to dispose of them provided they are not referenced anywhere else.
Clearing the collection will not instantly free any memory. The GC will only attempt to free memory when it needs to, as Saint said. Think of it like....investing in stock? If you put $100 into stock, and you see it's worth 1000 now, that doesn't mean for sure that you will take that money out then, right? If you see it raise or fall more, you may want to quickly though. If the GC doesn't see a -need- to free memory, it wont, and it shouldn't, because it has to interrupt the program to do so(making it slower..).
Connections are probably not your problem, it's possible, but I see it as far less likely.
Well hybrids videos are awesome, they explain alot and what could cause problems and so and he tells alot about collections wich I really like.
Its awesome.
Also he explains why u get alot random null exceptions.
Wich is awesome
I just <3 His videos.
could you point me to this video? I couldn't search for his name/thread
Quote:
Originally Posted by andyd123
If you clear a collection, it removes the objects from the collection, allowing the GC to dispose of them provided they are not referenced anywhere else.
Clearing the collection will not instantly free any memory. The GC will only attempt to free memory when it needs to, as Saint said. Think of it like....investing in stock? If you put $100 into stock, and you see it's worth 1000 now, that doesn't mean for sure that you will take that money out then, right? If you see it raise or fall more, you may want to quickly though. If the GC doesn't see a -need- to free memory, it wont, and it shouldn't, because it has to interrupt the program to do so(making it slower..).
Connections are probably not your problem, it's possible, but I see it as far less likely.
Well...when the ram usage reaches 1/1.2 GB it still doesn't go down at all...furthermore it will crash after this amount of RAM at any time...as it happens all the time
ZSZC SRO-DB Bot Memory Leak? 06/13/2010 - SRO Private Server - 7 Replies I'm using the .8 one since the .9 doesn't attack. But I'm just wondering, after say half an hour or so, the games gets extremely laggy. Does anyone have this issue as well and is it just due to a memory leak. Thanks!
5127 Memory Leak 06/08/2009 - Conquer Online 2 - 13 Replies Has anyone found a solution to the memory leak problem that started after patch 5127?
My clients has been experiencing a constant increase in the amount of RAM used by Conquer since patch 5127 have been installed. After looking in CO's official forum, I am pretty sure that it has not been cause by something from my side since many players have also having the same problem.
CO Partner Memory Leak? 06/18/2006 - Conquer Online 2 - 8 Replies Does it happen to any one else; after 5-10 mins of lvling it just ignores the mobs and random runs around.
4302 patch memory leak on hex edited exe 04/04/2006 - Conquer Online 2 - 4 Replies I just installed Patch 4302 and i get memory leak after i hex edited the Conquer.exe.. and ini mod doesnt seem to work for me.. any one any ideas?