|
-
Sep 20th, 2000, 05:54 AM
#1
Thread Starter
Lively Member
I'm making a program with a couple of very complicated classes. I hav some API calls too (using callbacks). The problem is. When I press F5 to run the program the first time it runs well. Next time I run it, it sometimes do a Dr Watson on me.
Will VB automaticly unload all the instances of the classes I have made in the program?
-
Sep 20th, 2000, 06:13 AM
#2
_______
<?>
No, you have to set your classes to nothing on exit.
In your exit routine.
Code:
'unload all forms and set to nothing
Dim frm As Form
Dim i As Integer
For i = 1 To Forms.Count - 1
Unload frm
Set frm = Nothing
Next i
'set all your classes to nothing
Set clsWhatever = Nothing
Set clsTwoNothing = Nothing
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
-
Sep 21st, 2000, 02:07 PM
#3
Dazed Member
Hey Joe Dont you mean.
Dim frm As Form
Dim i As Integer
For i = 0 To frm.Count - 1
Unload frm
Set frm = Nothing
Next i
Plus if im not mistaken this will generate
a run time error 91 "Object variable or
with block variable not set"
-
Sep 21st, 2000, 02:15 PM
#4
Dazed Member
This usually works for me.
private sub UnloadAll()
Dim Form As Form
For Each Form In forms
Unload Form
Set Form = Nothing
Next Form
End Sub
-
Sep 22nd, 2000, 09:34 AM
#5
Thread Starter
Lively Member
Need help to find the memory filler...
I have an example where i use a function returning a Collection object.
Code:
Public Sub Main()
Dim myColl As Collection
Set myColl = getColl2
MsgBox myColl.Item(1)
End Sub
Function getColl() As Collection
Set getColl = New Collection
getColl.Add "something"
End Function
Function getColl2() As Collection
Dim A As New Collection
A.Add "something"
Set getColl2 = A
Set A = Nothing
End Function
Both functions will return the same object, but when will the object cease to exist in memory?
I am experiencing out-of-memory problems with my code.
My understanding of SET and NEW:
Using SET actually sets a pointer to the object. It doesn't copy its contents. Using the NEW creates a new instance of the object and the SET sets a pointer to it.
Will VBs internal garbage can take care of the object when it is no longer pointed at, or will it stay there until the program exits?
The function getColl() creates an instance of the Collection object, but will the object ever get removed from memory, when it never gets a getColl2 = nothing ?
Anyone know an ultimate routine of some sort that can garbage anything created from the current program and that is no longer in use in memory?
I need to find the memory-filler in my code, and the only uncertain factors are the Collection object described above, and the use of the CopyMemory API:
[CODE]
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(lpvDest As Any, _
lpvSource As Any, _
ByVal cbCopy As Long)
Sub MySub()
Dim b(1 To 10) As Byte
CopyMemory b(1), ByVal StringPointerFromAnAPI, 10
For i = 1 To 10
Debug.Print Chr(b(i)); 'Prints the string to debug.
Next
End Function
[CODE]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|