CS Memory leak? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

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?

4th Mar 2017, 6:42 AM
Clém Grt
Clém Grt - avatar
2 Answers
+ 2
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!
5th Mar 2017, 9:31 AM
Ettienne Gilbert
Ettienne Gilbert - avatar
0
you are right it's a typo. thanks for the answer 👍
5th Mar 2017, 9:59 AM
Clém Grt
Clém Grt - avatar