'What's the proper way to garbage collect?
I have some TypeScript code where a variable is of a certain type and can't be assigned null nor undefined. If I want to reset its value, so that the previous one can be garbage collected, would it make sense to force it to undefined rather than an empty object, which is memory allocated for nothing?
type SomeType = { someProp?: number };
type MyType = { myProp: SomeType };
let variable: MyType = { myProp: { someProp: 5 } };
// What's the proper way to garbage collect?
// This
variable = { myProp: {} };
// Or this?
variable = {} as MyType;
// Or this?
variable = undefined as unknown as MyType;
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
