Skip to content

Commit b404560

Browse files
fix: networklist editor memory leak [backport] (#3148)
* fix This fixes the issue with NetworkLists on in-scene placed NetworkObjects causing small memory leaks when entering and exiting playmode. * update adding changelog entry * update adding PR number to log entry
1 parent 08e07df commit b404560

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Additional documentation and release notes are available at [Multiplayer Documen
1818

1919
### Fixed
2020

21+
- Fixed issue where `NetworkList` properties on in-scene placed `NetworkObject`s could cause small memory leaks when entering playmode. (#3148)
2122
- Fixed issue where a newly synchronizing client would be synchronized with the current `NetworkVariable` values always which could cause issues with collections if there were any pending state updates. Now, when initially synchronizing a client, if a `NetworkVariable` has a pending state update it will serialize the previously known value(s) to the synchronizing client so when the pending updates are sent they aren't duplicate values on the newly connected client side. (#3126)
2223
- Fixed issue where changing ownership would mark every `NetworkVariable` dirty. Now, it will only mark any `NetworkVariable` with owner read permissions as dirty and will send/flush any pending updates to all clients prior to sending the change in ownership message. (#3126)
2324
- Fixed issue with `NetworkVariable` collections where transferring ownership to another client would not update the new owner's previous value to the most current value which could cause the last/previous added value to be detected as a change when adding or removing an entry (as long as the entry removed was not the last/previously added value). (#3126)

com.unity.netcode.gameobjects/Runtime/NetworkVariable/Collections/NetworkList.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public NetworkList(IEnumerable<T> values = default,
4949
}
5050
}
5151

52+
~NetworkList()
53+
{
54+
Dispose();
55+
}
56+
5257
/// <inheritdoc />
5358
public override void ResetDirty()
5459
{
@@ -599,8 +604,17 @@ public int LastModifiedTick
599604
/// </summary>
600605
public override void Dispose()
601606
{
602-
m_List.Dispose();
603-
m_DirtyEvents.Dispose();
607+
if (m_List.IsCreated)
608+
{
609+
m_List.Dispose();
610+
}
611+
612+
if (m_DirtyEvents.IsCreated)
613+
{
614+
m_DirtyEvents.Dispose();
615+
}
616+
617+
base.Dispose();
604618
}
605619
}
606620

0 commit comments

Comments
 (0)