Valhalla Legends Forums Archive | Visual Basic Programming | Memory Leaks

AuthorMessageTime
Lenny
Is there anything in Visual Basic that can be done to solve this persistent problem in so many vb programs?

Perhaps some function that serves the same purpose as garbage collect in Java? Something that could clear values in memory that no longer have a pointer?
April 21, 2004, 1:23 AM
Myndfyr
A Garbage Collector isn't a language feature, it's a runtime feature. People need to remember that Java isn't only a language, but a platform. It might be dependent on other platforms, but it is still one in its own right. People call Novell a Network Operating System (NOS), but it doesn't run on its own.

However, I recommend you upgrade to VB .NET. You do get implicit garbage collection -- no extra work required. This is based on the .NET Platform though -- it is not a part of VB 6 or older.
April 21, 2004, 1:54 AM
Grok
[quote author=Lenny link=board=5;threadid=6400;start=0#msg56029 date=1082510598]
Is there anything in Visual Basic that can be done to solve this persistent problem in so many vb programs?

Perhaps some function that serves the same purpose as garbage collect in Java? Something that could clear values in memory that no longer have a pointer?
[/quote]

VB6 Memory Leaks? Do tell! Show me how you are creating these.
April 21, 2004, 2:05 AM
Lenny
After a long period of running my VB programs, they seem to build up more and more memory usage...Much faster than any other non vb programs....

I'm not storing any variables that consistently get larger and larger as time goes by, I assumed the large usage was due to storing values that are no longer used.....
April 21, 2004, 2:36 AM
Tuberload
[quote author=Lenny link=board=5;threadid=6400;start=0#msg56042 date=1082514988]
After a long period of running my VB programs, they seem to build up more and more memory usage...Much faster than any other non vb programs....

I'm not storing any variables that consistently get larger and larger as time goes by, I assumed the large usage was due to storing values that are no longer used.....
[/quote]

Do you ever clear the rtb that stores the data recieved from battle.net? This was the main reason my bot took up so much memory. (When I programmed in VB that is)
April 21, 2004, 3:01 AM
Lenny
Actually, yes, my bot automatically removes the oldest lines of text once it reaches a user defined limit...
April 21, 2004, 3:06 AM
Tuberload
[quote author=Lenny link=board=5;threadid=6400;start=0#msg56047 date=1082516803]
Actually, yes, my bot automatically removes the oldest lines of text once it reaches a user defined limit...
[/quote]

Geez, didn't mean to suggest something you're already doing. Next time I won't offer any help.
April 21, 2004, 4:07 AM
Lenny
That reply didnt seem hostile at all...
I was just mentioning it shouldnt be one of the causes of the growing memory usage...
April 21, 2004, 4:16 AM
Grok
[quote author=Lenny link=board=5;threadid=6400;start=0#msg56054 date=1082520974]
That reply didnt seem hostile at all...
I was just mentioning it shouldnt be one of the causes of the growing memory usage...
[/quote]

So run it in debug mode and break out after a few hours to see what is taking up so much memory? Try your local variables window, for starters. I think it shows globals too.
April 21, 2004, 4:19 AM
Tuberload
[quote author=Lenny link=board=5;threadid=6400;start=0#msg56054 date=1082520974]
That reply didnt seem hostile at all...
I was just mentioning it shouldnt be one of the causes of the growing memory usage...
[/quote]

I didn't say it sounded hostile, you just sounded offended I would even bring that up.
April 21, 2004, 4:24 AM
Adron
[quote author=Grok link=board=5;threadid=6400;start=0#msg56036 date=1082513149]
VB6 Memory Leaks? Do tell! Show me how you are creating these.
[/quote]

You can easily create memory leaks in VB. All you have to do is make some objects that reference each other and then drop your own references to them.
April 21, 2004, 10:07 AM
iago
hmm, incidentally, I'm going to move this to VB forum
April 21, 2004, 2:07 PM
Telos
Ive found that if youre optimizing your VB programs for memory usage encapsulating everything in classes is the best way to go but you incur a performance penalty for adding a layer of abstraction. The other thing I do is to explicitly remove references to class objects when Im through this way I dont end up with looped objects as Adron described
April 21, 2004, 3:23 PM
Grok
[quote author=Adron link=board=31;threadid=6400;start=0#msg56098 date=1082542078]
[quote author=Grok link=board=5;threadid=6400;start=0#msg56036 date=1082513149]
VB6 Memory Leaks? Do tell! Show me how you are creating these.
[/quote]

You can easily create memory leaks in VB. All you have to do is make some objects that reference each other and then drop your own references to them.
[/quote]

What's so easy about it?
[code]Dim objX As Object, objX1 As Object, objX2 As Object
Dim intMod2 As Integer
For lPos = 1 To 100
Set objX = CreateObject("Project.Class")
intMod2 = lPos Mod 2
If intMod2 = 1 Then
Set objX1 = objX
Else
Set objX2 = objX
Set objX1.otherguy = objX2
Set objX2.otherguy = objX1
End If
Next lPos
Set objX1 = Nothing
Set objX2 = Nothing[/code]

You have to get pretty sloppy to do that?
April 21, 2004, 5:31 PM
LoRd
[quote author=Lenny link=board=31;threadid=6400;start=0#msg56042 date=1082514988]
After a long period of running my VB programs, they seem to build up more and more memory usage...Much faster than any other non vb programs....
[/quote]

I've ran my Visual Basic-made programs for weeks at a time without experiencing any problems.
April 21, 2004, 5:33 PM
Adron
[quote author=Grok link=board=31;threadid=6400;start=0#msg56143 date=1082568688]
You have to get pretty sloppy to do that?
[/quote]

If you build yourself a huge tree of objects that reference each others in intricate ways, I can see a loop happening easily. Circular references happen naturally when you get lots of objects notifying each other about things.

Edit:

Other example: Create a binary tree where each node is an object and has pointers to its child nodes and parent node so you can walk the tree any way you like. Eibro has a C++ one of those as in his assignment for Skywing.

If you make such a structure in VB and don't walk through the tree removing the nodes when you want to get rid of the structure, you've made yourself a memory leak.

April 21, 2004, 7:36 PM

Search