ByVal, ByRef

ccc

Newcomer
Joined
Dec 13, 2002
Messages
8
Okay, I know what byVal and byRef do, ByVal passes a copy of an object, and ByRef passes the actual object, but lets say I have this code:

Visual Basic:
Class myTest
Event myEvent(ByVal sender as myTest)
sub FireEvent()
RaiseEvent myEvent(me)
end sub
End Class

sub RunTest()
dim mTest as new myTest
addhandler mTest.myEvent, addressof del_myEvent
mTest.FireEvent
end sub

sub del_myEvent(byval sender as myTest)
RemoveHandler sender.myEvent,addressof del_myevent
end sub

Will the object mTest's handler be unassigned correctly? Or since i've passed a copy of the object, the original will still fire again? Should I just stick to writing everything byref instead? My application seems to eat up alot of memory, because something is getting stuck and not used. It uses a similar structure to the code above. Any tips?

Any help would be appreciated. Thanks. :confused:
 
Your class is a reference type, so it'll always be passed by reference. Only value types (structures and the primitives) can actually be passed by value.
 
Back
Top