Skip to content

Commit 9126fa1

Browse files
committed
being super paranoid about memory
1 parent 901fae4 commit 9126fa1

9 files changed

Lines changed: 98 additions & 5 deletions

File tree

CathodeLib/Scripts/CATHODE/Commands.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public class Commands : CathodeFile
2525
public static new Implementation Implementation = Implementation.CREATE | Implementation.LOAD | Implementation.SAVE;
2626
public Commands(string path) : base(path) { }
2727

28+
~Commands()
29+
{
30+
Entries.Clear();
31+
}
32+
2833
// This is always:
2934
// - Root Instance (the map's entry composite, usually containing entities that call mission/environment composites)
3035
// - Global Instance (the main data handler for keeping track of mission number, etc - kinda like a big singleton)

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Composite.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ public Composite(string name)
1919
this.name = name;
2020
}
2121

22+
~Composite()
23+
{
24+
variables.Clear();
25+
functions.Clear();
26+
aliases.Clear();
27+
proxies.Clear();
28+
}
29+
2230
public ShortGuid shortGUID; //The id when this composite is used as an entity in another composite
2331
public string name = ""; //The string name of the composite
2432

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Entity.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using System.Numerics;
1515
using System.IO;
1616
using CathodeLib;
17+
using CathodeLib.Properties;
1718
#endif
1819

1920
namespace CATHODE.Scripting.Internal
@@ -42,6 +43,12 @@ public Entity(ShortGuid shortGUID, EntityVariant variant)
4243
public List<EntityConnector> childLinks = new List<EntityConnector>();
4344
public List<Parameter> parameters = new List<Parameter>();
4445

46+
~Entity()
47+
{
48+
childLinks.Clear();
49+
parameters.Clear();
50+
}
51+
4552
/* Implements IComparable for searching */
4653
public int CompareTo(Entity other)
4754
{
@@ -224,6 +231,11 @@ public class FunctionEntity : Entity
224231
public FunctionEntity() : base(EntityVariant.FUNCTION) { }
225232
public FunctionEntity(ShortGuid shortGUID) : base(shortGUID, EntityVariant.FUNCTION) { }
226233

234+
~FunctionEntity()
235+
{
236+
resources.Clear();
237+
}
238+
227239
public FunctionEntity(string function, bool autoGenerateParameters = false) : base(EntityVariant.FUNCTION)
228240
{
229241
this.function = ShortGuidUtils.Generate(function);

CathodeLib/Scripts/CATHODE/CommandsPAK/Components/Parameter.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@ public Parameter(ShortGuid id, ParameterData data, ParameterVariant var = Parame
2525
public ShortGuid name;
2626
public ParameterData content = null;
2727
public ParameterVariant variant = ParameterVariant.PARAMETER;
28+
29+
~Parameter()
30+
{
31+
content = null;
32+
}
2833
}
2934
}

CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/EntityUtils.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public static class EntityUtils
2020
private static EntityNameTable _vanilla;
2121
private static EntityNameTable _custom;
2222

23+
public static Commands LinkedCommands => _commands;
2324
private static Commands _commands;
2425

2526
/* Load all standard entity/composite names from our offline DB */
@@ -45,11 +46,10 @@ public static void LinkCommands(Commands commands)
4546
}
4647

4748
_commands = commands;
48-
if (_commands != null)
49-
{
50-
_commands.OnLoadSuccess += LoadCustomNames;
51-
_commands.OnSaveSuccess += SaveCustomNames;
52-
}
49+
if (_commands == null) return;
50+
51+
_commands.OnLoadSuccess += LoadCustomNames;
52+
_commands.OnSaveSuccess += SaveCustomNames;
5353

5454
LoadCustomNames(_commands.Filepath);
5555
}

CathodeLib/Scripts/CATHODE/CommandsPAK/Helpers/ShortGuidUtils.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public static class ShortGuidUtils
1616
private static GuidNameTable _vanilla = null;
1717
private static GuidNameTable _custom = null;
1818

19+
public static Commands LinkedCommands => _commands;
1920
private static Commands _commands;
2021

2122
/* Pull in strings we know are cached as ShortGuid in Cathode */

CathodeLib/Scripts/CATHODE/Models.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public Models(string path) : base(path) { }
2121
private List<CS2.Component.LOD.Submesh> _writeList = new List<CS2.Component.LOD.Submesh>();
2222
private string _filepathBIN;
2323

24+
~Models()
25+
{
26+
Entries.Clear();
27+
_writeList.Clear();
28+
}
29+
2430
#region FILE_IO
2531
/* Load the file */
2632
override protected bool LoadInternal()
@@ -623,6 +629,11 @@ public class CS2
623629
public string Name;
624630
public List<Component> Components = new List<Component>();
625631

632+
~CS2()
633+
{
634+
Components.Clear();
635+
}
636+
626637
public class Component
627638
{
628639
public List<LOD> LODs = new List<LOD>();
@@ -632,6 +643,11 @@ public class Component
632643
public int UnkLv426Pt1 = 0;
633644
public int UnkLv426Pt2 = 0;
634645

646+
~Component()
647+
{
648+
LODs.Clear();
649+
}
650+
635651
public class LOD
636652
{
637653
public LOD(string name)
@@ -642,6 +658,11 @@ public LOD(string name)
642658
public string Name;
643659
public List<Submesh> Submeshes = new List<Submesh>();
644660

661+
~LOD()
662+
{
663+
Submeshes.Clear();
664+
}
665+
645666
public class Submesh
646667
{
647668
public Vector3 AABBMin = new Vector3(-1,-1,-1); // <---- When importing a new model, setting these all to zero seem to make it invisible??
@@ -675,6 +696,12 @@ public class Submesh
675696
public List<int> boneIndices = new List<int>();
676697

677698
public byte[] content = new byte[0];
699+
700+
~Submesh()
701+
{
702+
boneIndices.Clear();
703+
content = null;
704+
}
678705
}
679706

680707
public override string ToString()

CathodeLib/Scripts/CATHODE/Shaders.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ public Shaders(string path) : base(path) { }
2121
private string _filepathBIN;
2222
private string _filepathIDX;
2323

24+
~Shaders()
25+
{
26+
Entries.Clear();
27+
}
28+
2429
#region FILE_IO
2530
override protected bool LoadInternal()
2631
{
@@ -534,6 +539,19 @@ public class Shader
534539
public byte[] GeometryShader;
535540
public byte[] ComputeShader;
536541

542+
~Shader()
543+
{
544+
Unknown2.Clear();
545+
Unknown3.Clear();
546+
547+
VertexShader = null;
548+
PixelShader = null;
549+
HullShader = null;
550+
DomainShader = null;
551+
GeometryShader = null;
552+
ComputeShader = null;
553+
}
554+
537555
public class UnknownPair
538556
{
539557
public int unk1;

CathodeLib/Scripts/CATHODE/Textures.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ public Textures(string path) : base(path) { }
1717
public List<TEX4> _writeList = new List<TEX4>();
1818
private string _filepathBIN;
1919

20+
~Textures()
21+
{
22+
Entries.Clear();
23+
_writeList.Clear();
24+
}
25+
2026
#region FILE_IO
2127
override protected bool LoadInternal()
2228
{
@@ -267,6 +273,12 @@ public class TEX4
267273
public Part tex_LowRes = new Part();
268274
public Part tex_HighRes = new Part();
269275

276+
~TEX4()
277+
{
278+
tex_LowRes = null;
279+
tex_HighRes = null;
280+
}
281+
270282
public class Part
271283
{
272284
public Int16 Width = 0;
@@ -282,6 +294,11 @@ public class Part
282294
public UInt16 unk2 = 0;
283295
public UInt32 unk3 = 0;
284296
public UInt32 unk4 = 0;
297+
298+
~Part()
299+
{
300+
Content = null;
301+
}
285302
}
286303
}
287304

0 commit comments

Comments
 (0)