|
-
December 30th, 2008, 08:08 PM
#4
Re: Help creating interface.
The garbage collector in .Net will only free up the memory used by objects after the last reference to the object is removed. I assume your Unregister() method removes references from a list so there's nothing else you can add to that to deal with memory leaks. I'm not sure what you mean by adding Dispose to it. Dispose is a required function for objects that implement IDisposable. But that doesn't guarantee cleanup if you forget to call Unregister() for every object. You could wrap that in a Using/End Using. However, you still have to remember to use Using/End Using each time. I'm still not sure what you are trying to do. However, I don't think tracking all these objects is the solution.
I briefly looked at the members of the garbage collector but I don't see anything that would list all the objects it's managing. If there was you could loop through and find all instances of your object. However, you should leave the GC along. It works just fine unless your doing something bad.
Reflection won't help at all since it's job is to examine data types. It doesn't do anything with instances of objects.
I kinda' get the impression that you are loading a file that list instructions for doing things. Maybe the following code will help.
Code:
Public Class Instructions
Public Instructions As New List(Of Instruction)
Public Sub ProcessInstructions()
For Each Instruction In Instructions
Instruction.ProcessData()
Next
End Sub
End Class
Public MustInherit Class Instruction
Protected Data As String
Public MustOverride Sub ProcessData()
End Class
Public Class Soup
Inherits Instruction
Public Overrides Sub ProcessData()
If Data = "Chicken" Then
MakeChickenSoup()
End If
End Sub
End Class
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
|