DEV Community

Discussion on: I'm an Expert in Memory Management & Segfaults, Ask Me Anything!

Collapse
 
amineamami profile image
amineamami

what’s the simplest way to cause memory leak ?

Collapse
 
codemouse92 profile image
Jason C. McDonald • Edited

Fail to free memory after you allocate it, and then destroy and the pointer.

My return question is, why would you want to? ;-)

Collapse
 
daemoen profile image
Marc Mercer

Ironically, you of all people should have a very easy answer to your own question -- 'Why would you want to?' -- To learn more about what went wrong? To study it, to understand it, and to prevent it from happening again in the future. Sometimes, the best way of learning is by knowingly doing something 'silly' -- I wouldn't call it stupid because you are doing it with the expectation, which means you are preparing for it. All good engineers try to reach this state -- be aware of what can go wrong, and how to handle it.

Thread Thread
 
codemouse92 profile image
Jason C. McDonald

Yes, that's fair, in learning. But, honestly, 99% of my learning comes from just trying to do hard things, and working with the failures as they come. Those are far more practical and effective to learn from than any sort of deliberately manufactured mistake.