Fix memory leak from object pools.

This commit is contained in:
2023-04-21 12:18:29 +08:00
parent c39a02a1c2
commit 2784544884
4 changed files with 27 additions and 10 deletions

View File

@@ -524,6 +524,8 @@ namespace Cryville.Crtr {
Game.AudioClient.Start();
Game.AudioSession = Game.AudioSequencer.NewSession();
inputProxy.Deactivate();
inputProxy = null;
judge = null;
if (nbus != null) { nbus.Dispose(); nbus = null; }
if (tbus != null) { tbus.Dispose(); tbus = null; }
if (bbus != null) { bbus.Dispose(); bbus = null; }

View File

@@ -178,7 +178,7 @@ namespace Cryville.Crtr.Event {
if (s.CloneType == 2) SetGraphicalActive(false, s);
else SetPreGraphicalActive(false, s);
}
anchorEvPool.Return(tev);
ReturnAnchorEvent(tev);
}
else if (RootTransform && s.CloneType == 2) MatchDynamic(s, 2);
}
@@ -245,9 +245,14 @@ namespace Cryville.Crtr.Event {
}
public virtual void Discard(ContainerState s, StampedEvent ev) {
if (ev is StampedEvent.Anchor) {
anchorEvPool.Return((StampedEvent.Anchor)ev);
ReturnAnchorEvent((StampedEvent.Anchor)ev);
}
}
void ReturnAnchorEvent(StampedEvent.Anchor ev) {
ev.Container = null;
ev.Target = null;
anchorEvPool.Return(ev);
}
#endregion
#endregion

View File

@@ -321,10 +321,10 @@ namespace Cryville.Crtr.Event {
public void Discard(StampedEvent ev) {
Handler.Discard(this, ev);
if (ev is StampedEvent.RelativeMotion) {
relmEvPool.Return((StampedEvent.RelativeMotion)ev);
ReturnRelativeMotionEvent((StampedEvent.RelativeMotion)ev);
}
else if (ev.Origin is StampedEvent.RelativeMotion) {
erelmEvPool.Return((StampedEvent.Temporary)ev);
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
}
}
@@ -353,7 +353,7 @@ namespace Cryville.Crtr.Event {
if (ev.Duration == 0) {
PlayingMotions.Remove(ev);
_rmvpa.Return(mv);
relmEvPool.Return(tev);
ReturnRelativeMotionEvent(tev);
}
}
else if (ev.Unstamped is EventContainer) {
@@ -372,8 +372,8 @@ namespace Cryville.Crtr.Event {
var mv = PlayingMotions[oev];
if (mv.CloneTypeFlag == CloneType) _rmvpa.Return(mv);
PlayingMotions.Remove(oev);
erelmEvPool.Return((StampedEvent.Temporary)ev);
relmEvPool.Return((StampedEvent.RelativeMotion)oev);
ReturnEndRelativeMotionEvent((StampedEvent.Temporary)ev);
ReturnRelativeMotionEvent((StampedEvent.RelativeMotion)oev);
}
else {
var nev = oev.Unstamped;
@@ -521,7 +521,6 @@ namespace Cryville.Crtr.Event {
ev.Container = Container;
ev.Name = m.Key;
ev.Node = node.Value;
ev.ReleaseEvent = null;
bus.PushTempEvent(ev);
if (node.Value.EndTime.Value > node.Value.Time.Value) {
var eev = erelmEvPool.Rent();
@@ -534,6 +533,17 @@ namespace Cryville.Crtr.Event {
}
}
}
void ReturnRelativeMotionEvent(StampedEvent.RelativeMotion ev) {
ev.Container = null;
ev.Node = null;
ev.ReleaseEvent = null;
relmEvPool.Return(ev);
}
void ReturnEndRelativeMotionEvent(StampedEvent.Temporary ev) {
ev.Container = null;
ev.Origin = null;
erelmEvPool.Return(ev);
}
#endregion
}
}

View File

@@ -123,7 +123,7 @@ namespace Cryville.Crtr {
readonly IntKeyedDictionary<PropSrc>[] ContextCascade = new IntKeyedDictionary<PropSrc>[256];
int _cascadeHeight;
public void ContextCascadeInsert() {
ContextCascade[_cascadeHeight++].Clear();
_cascadeHeight++;
}
public void ContextCascadeInsert(IntKeyedDictionary<PropSrc> srcs) {
ContextCascadeInsert();
@@ -143,7 +143,7 @@ namespace Cryville.Crtr {
return null;
}
public void ContextCascadeDiscard() {
--_cascadeHeight;
ContextCascade[--_cascadeHeight].Clear();
}
public PdtEvaluator() {