c# - How do I implement Dispose() in my class correctly? -
I am seeking advice on how and when the settlement pattern is applied.
I have read the MSDN article on how to apply the settlement () pattern, it makes sense. I have implemented it in my class, but it seems that the use of memory does not matter.
A bit of background, I'm building a 2D above game engine. I have units named Gatheer, which have inherited from the actor (a basic class for tracking phantom drawing and viewplan), and they are simple sprites that go out and work. They disappear after 5 game rounds of the game.
I use a list to track the gallery, it's implemented like this:
list & lt; Gatheer & gt; Collect list = new list & lieutenant; Gatheer & gt; (); Then I sorted the list inside the game engine like this:
for public zero pruneDeadFollowers () (for int i = gatherList.Count-1 ; I & gt; -1; i--) {If (List of gathered [i] .timeToDie) // To verify that the unit should be removed from this period. {This.dropActor (List of gathered [i ]; // Call the method that ends the object with trigger events. GatherList [i] .dispose (); // is it necessary? Get rid of the add.List.RemoveAt (i); // from the list.}}} The Gatherer object is very simple The components have been managed.
There are so many int fields, some lists, points (from the monogam), the two objects of the ball objects and many static int. I also have random R, built on runtime, but it seems I do not have a displacement method. I have only unmanaged objects, which are 2 Texture2D objects I Public Texture 2D Brightness Structure; Public Texture2D texImage;
At my disposal, I think That I only need to settle the texture.
The problem is that if I actually call texImage. This destroys the texture for other units which are still alive. I think I can make a tap instead, which does not affect the existing units.
I have to settle it: is it enough? If not, how can I verify that it is working as necessary? GC.SuppressFinalize (this);} Protected implementation of settlement pattern Protects virtual zeros (disposal of hair) (if disposed of) (if disposed) Returns; if (settlement) {glowTexture = null; TexImage = null;} dealt = true;}
Your implementation is valid but not really enough.
Dissection is used to issue unmanaged resources, as You have found that your initial implementation (where you settled the texture after using them) was correct.
except You are sharing those resources in many objects Therefore, you do not want to use objects texture to control your life.
I will follow the pattern in XNA, whatever the material loads, it also needs to be unloaded. In your case, anyone who creates texture (and thus the child's objects) should remove them using texture. Child objects must actually be in the form of IDisposable I do not need to implement with anything I can see.
Comments
Post a Comment