Implement IDisposable on Window/WindowArea

This commit is contained in:
Drew DeVault 2015-06-22 14:23:54 -06:00
parent 9d01f77625
commit 2dd80cdd0d
6 changed files with 22 additions and 7 deletions

View File

@ -2,7 +2,7 @@
namespace TrueCraft.API.Windows
{
public interface IWindow
public interface IWindow : IDisposable
{
event EventHandler<WindowChangeEventArgs> WindowChange;
@ -33,4 +33,4 @@ namespace TrueCraft.API.Windows
/// </summary>
void CopyToInventory(IWindow inventoryWindow);
}
}
}

View File

@ -2,7 +2,7 @@
namespace TrueCraft.API.Windows
{
public interface IWindowArea
public interface IWindowArea : IDisposable
{
event EventHandler<WindowChangeEventArgs> WindowChange;
@ -17,4 +17,4 @@ namespace TrueCraft.API.Windows
void CopyTo(IWindowArea area);
int MoveOrMergeItem(int index, ItemStack item, IWindowArea from);
}
}
}

View File

@ -202,7 +202,7 @@ namespace TrueCraft.Core.Logic.Blocks
newEntity["Items"] = entityAdjacent;
world.SetTileEntity(adjacent, newEntity);
}
}; // TODO: Memory leak here, make windows implement IDisposable
};
user.OpenWindow(window);
return false;
}
@ -224,4 +224,4 @@ namespace TrueCraft.Core.Logic.Blocks
base.BlockMined(descriptor, face, world, user);
}
}
}
}

View File

@ -7,7 +7,7 @@ using TrueCraft.API;
namespace TrueCraft.Core.Windows
{
public abstract class Window : IWindow
public abstract class Window : IWindow, IDisposable
{
public abstract IWindowArea[] WindowAreas { get; protected set; }
@ -141,5 +141,14 @@ namespace TrueCraft.Core.Windows
if (WindowChange != null)
WindowChange(this, e);
}
public virtual void Dispose()
{
for (int i = 0; i < WindowAreas.Length; i++)
{
WindowAreas[i].Dispose();
}
WindowChange = null;
}
}
}

View File

@ -96,5 +96,10 @@ namespace TrueCraft.Core.Windows
if (WindowChange != null)
WindowChange(this, e);
}
public virtual void Dispose()
{
WindowChange = null;
}
}
}

View File

@ -216,6 +216,7 @@ namespace TrueCraft
if (!clientInitiated)
QueuePacket(new CloseWindowPacket(CurrentWindow.ID));
CurrentWindow.CopyToInventory(Inventory);
CurrentWindow.Dispose();
CurrentWindow = InventoryWindow;
}