CS Memory leak? | SoloLearn: Learn to code for FREE!


CS Memory leak?

does this code creates memory leak? struct STRUCT_A { int n; } Class B { ... list <STRUCT_A> lStructA; void store(int x) { STRUCT_A SA = new STRUCT_A(); SA.n = x; lStructA.add(n); } ... }; main(...) { B bobj = new B(); B.store (2); ... } i would say no, because a struct is passed by value... what do you think?

3/4/2017 6:42:00 AM

Clém Grt

2 Answers

New Answer


I assume that... lStructA.add(n); ... is a typo (from the code you have shown it will be a compilation error) , and what you meant is: lStructA.add(SA); If that is the case your reasoning is correct and it all looks good to me!


you are right it's a typo. thanks for the answer 👍