Skip to content

Commit d7df73b

Browse files
fix: networklist editor memory leak (#3147)
* fix This fixes the issue with NetworkLists on in-scene placed NetworkObjects causing small memory leaks when entering and exiting playmode. * update adding change log entry * style removing white spaces * style removing added CR/LF entries. * update adding PR number to log entry
1 parent dfabbed commit d7df73b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

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

1616
### Fixed
1717

18+
- Fixed issue where `NetworkList` properties on in-scene placed `NetworkObject`s could cause small memory leaks when entering playmode. (#3147)
1819
- Fixed in-scene `NertworkObject` synchronization issue when loading a scene with currently connected clients connected to a session created by a `NetworkManager` started as a server (i.e. not as a host). (#3133)
1920
- Fixed issue where a `NetworkManager` started as a server would not add itself as an observer to in-scene placed `NetworkObject`s instantiated and spawned by a scene loading event. (#3133)
2021
- Fixed issue where spawning a player using `NetworkObject.InstantiateAndSpawn` or `NetworkSpawnManager.InstantiateAndSpawn` would not update the `NetworkSpawnManager.PlayerObjects` or assign the newly spawned player to the `NetworkClient.PlayerObject`. (#3122)

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

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

53+
~NetworkList()
54+
{
55+
Dispose();
56+
}
57+
5358
/// <inheritdoc />
5459
public override void ResetDirty()
5560
{
@@ -624,8 +629,16 @@ public int LastModifiedTick
624629
/// </summary>
625630
public override void Dispose()
626631
{
627-
m_List.Dispose();
628-
m_DirtyEvents.Dispose();
632+
if (m_List.IsCreated)
633+
{
634+
m_List.Dispose();
635+
}
636+
637+
if (m_DirtyEvents.IsCreated)
638+
{
639+
m_DirtyEvents.Dispose();
640+
}
641+
629642
base.Dispose();
630643
}
631644
}

0 commit comments

Comments
 (0)