/// <summary> /// Several arrays and other fields hold references to various classes from mods, we need to clean them up to give properly coded mods a chance to be completely free of references /// so that they can be collected by the garbage collection. For most things eventually they will be replaced during gameplay, but we want the old instance completely gone quickly. /// </summary> internal static void CleanupModReferences() { // Clear references to ModPlayer instances for (int i = 0; i < Main.player.Length; i++) { Main.player[i] = new Player(); // player.whoAmI is only set for active players } Main.clientPlayer = new Player(false); Main.ActivePlayerFileData = new Terraria.IO.PlayerFileData(); Main._characterSelectMenu._playerList?.Clear(); Main.PlayerList.Clear(); for (int i = 0; i < Main.npc.Length; i++) { Main.npc[i] = new NPC(); Main.npc[i].whoAmI = i; } for (int i = 0; i < Main.item.Length; i++) { Main.item[i] = new Item(); // item.whoAmI is never used } if (ItemSlot.singleSlotArray[0] != null) { ItemSlot.singleSlotArray[0] = new Item(); } for (int i = 0; i < Main.chest.Length; i++) { Main.chest[i] = new Chest(); } for (int i = 0; i < Main.projectile.Length; i++) { Main.projectile[i] = new Projectile(); // projectile.whoAmI is only set for active projectiles } TileEntity.Clear(); // drop all possible references to mod TEs }