Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
Adding Dispose to parsers.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessefreeman committed Feb 5, 2020
1 parent c060f36 commit 3cdcb4c
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 2 deletions.
12 changes: 12 additions & 0 deletions Runners/PixelVision8/Runner/Exporters/ColorPaletteExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ public void NextStep()
exporter.NextStep();
}

public void StepCompleted()
{
exporter.StepCompleted();
}

public void Dispose()
{
exporter.Dispose();
colorChip = null;
exporter = null;
}

public byte[] bytes => exporter.bytes;

public string fileName => exporter.fileName;
Expand Down
14 changes: 14 additions & 0 deletions Runners/PixelVision8/Runner/Exporters/SpriteExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ public void NextStep()
exporter.NextStep();
}

public void StepCompleted()
{
exporter.StepCompleted();
}

public void Dispose()
{
exporter.Dispose();
engine = null;
spriteChip = null;
imageExporter = null;
exporter = null;
}

public byte[] bytes => exporter.bytes;

public string fileName => exporter.fileName;
Expand Down
7 changes: 7 additions & 0 deletions SDK/Runner/Parsers/AbstractParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,12 @@ public virtual void StepCompleted()
{
currentStep++;
}

public virtual void Dispose()
{
bytes = null;
FileLoadHelper = null;
steps.Clear();
}
}
}
3 changes: 3 additions & 0 deletions SDK/Runner/Parsers/IAbstractParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,8 @@ public interface IAbstractParser
bool completed { get; }
void CalculateSteps();
void NextStep();
void StepCompleted();
void Dispose();

}
}
1 change: 1 addition & 0 deletions SDK/Runner/Parsers/IImageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ public interface IImageParser
void ReadHeader();
void ReadStream();
void ReadBytes(byte[] bytes);
void Dispose();
}
}
6 changes: 6 additions & 0 deletions SDK/Runner/Parsers/ImageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,11 @@ public void ParseImageData()

currentStep++;
}

public override void Dispose()
{
base.Dispose();
imageParser = null;
}
}
}
12 changes: 12 additions & 0 deletions SDK/Runner/Parsers/PNGReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,5 +358,17 @@ private int CalculateBytesPerPixel()
throw new Exception("Unknown color type.");
}
}

public void Dispose()
{
_colorPalette.Clear();
_colors = null;
bytes = null;
chunks.Clear();
dataChunks.Clear();
memoryStream.Dispose();
palette = null;
pixels = null;
}
}
}
7 changes: 7 additions & 0 deletions SDK/Runner/Parsers/SpriteParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,12 @@ public virtual void ConvertColorsToIndexes(int totalColors)
spriteData[i] = tmpRefID;
}
}

public override void Dispose()
{
base.Dispose();
chips = null;
spriteChip = null;
}
}
}
14 changes: 12 additions & 2 deletions SDK/Runner/Services/LoadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,19 +189,29 @@ public void AddParser(IAbstractParser parser)
public void LoadAll()
{
while (Completed == false) NextParser();

parsers.Clear();
}

public void NextParser()
{
if (Completed) return;
if (Completed)
{
parsers.Clear();
return;
}

var parser = parsers[currentParserID];

parser.NextStep();

currentStep++;

if (parser.completed) currentParserID++;
if (parser.completed)
{
parser.Dispose();
currentParserID++;
}
}

public void StartLoading()
Expand Down

0 comments on commit 3cdcb4c

Please sign in to comment.