Skip to content

Commit 1c2c547

Browse files
committed
instance sharing: prevent early garbage collection
1 parent 7148fc0 commit 1c2c547

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

Assets/Colyseus/Runtime/Colyseus/Serializer/Schema/ReferenceTracker.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,23 @@ public bool Has(int refId)
8080
/// Remove a reference by ID
8181
/// </summary>
8282
/// <param name="refId">The ID of the reference to remove</param>
83-
public void Remove(int refId)
83+
public bool Remove(int refId)
8484
{
8585
if (!refCounts.ContainsKey(refId))
8686
{
8787
Debug.Log("trying to remove refId that doesn't exist: " + refId);
88-
return;
88+
return false;
8989
}
9090

9191
refCounts[refId] = refCounts[refId] - 1;
9292

9393
if (refCounts[refId] <= 0)
9494
{
9595
deletedRefs.Add(refId);
96+
return true;
9697
}
98+
99+
return false;
97100
}
98101

99102
/// <summary>
@@ -118,9 +121,8 @@ public void GarbageCollection()
118121
if (fieldValue is IRef)
119122
{
120123
int childRefId = ((IRef)fieldValue).__refId;
121-
if (!deletedRefs.Contains(childRefId))
124+
if (!deletedRefs.Contains(childRefId) && Remove(childRefId))
122125
{
123-
Remove(childRefId);
124126
totalDeletedRefs++;
125127
}
126128
}
@@ -131,9 +133,8 @@ public void GarbageCollection()
131133
((ISchemaCollection)_ref).ForEach((key, value) =>
132134
{
133135
int childRefId = ((IRef)value).__refId;
134-
if (!deletedRefs.Contains(childRefId))
136+
if (!deletedRefs.Contains(childRefId) && Remove(childRefId))
135137
{
136-
Remove(childRefId);
137138
totalDeletedRefs++;
138139
}
139140
});

Assets/Colyseus/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "io.colyseus.sdk",
3-
"version": "0.16.5",
3+
"version": "0.16.6",
44
"displayName": "Colyseus SDK",
55
"description": "Colyseus Multiplayer SDK for Unity",
66
"unity": "2019.1",

0 commit comments

Comments
 (0)