Use if statements to micromanage stack
c#
Solution
Based on the usage, I'm assuming `DefinedObjectFactory` is a class, not a struct. Therefore, the only thing that's on the stack is a reference to `DefinedObjectFactory`. The actual object is on the heap, and is controlled by the garbage collector.
The only stack space you're potentially saving is the space for a single pointer, so it's not worth it.
Problem
Should if statements be used to assist in the stack's memory de-allocation? Example A: ``` var objectHolder = new ObjectHolder(); if (true) { List<DefinedObject> objectList; using (var sr = new GenericStreamReader<DefinedObject>()) { objectList= sr.Get().ToList(); } if (true) { var DOF = new DefinedObjectFactory(); objectHolder.DefinedObjects = DOF.DefineObjects(objectList); } } //example endpoint ``` Example B: ``` var objectHolder = new ObjectHolder(); List<DefinedObject> objectList; using (var sr = new GenericStreamReader<DefinedObject>()) { objectList= sr.Get().ToList(); } var DOF = new DefinedObjectFactory(); objectHolder.DefinedObjects = DOF.DefineObjects(objectList); //example endpoint ``` Will Example A have a lighter footprint on the stack when example endpoint is reached versus when example endpoint is reached in Example B??