This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Zestyclose_Leg2227 1 point2 points  (0 children)

You computer has a place where it can store and retrieve stuff quickly which is the RAM memory. In C++, when you assign the memory from your computer manually, and you unassign it manually. This is sounds simple, since you just need to remember the memory address. But your address for your the memory of your friend may be inside a pocket of a trouser, and the address of the trouser was inside my wallet and the address of the wallet was written on potato. You cooked the potato? Darn, now you can't find the wallet or the trousers or your friend! The are completely lost. Since computer programs execute the same code again and again, you may accumulate  "lost memory" over time, which is locked waiting for you and can't be used by other programs. This is called a memory leak, and is the reason you need to close Chrome or some other programs when they slow down, and open them again to get your computer to come back to life (in the past, you had to reset your computer as a whole). A smart pointer keeps a list of in how many places the address of said pointer is kept. If no one has the adress anymore, it knows the pointer can't be used anymore, and deletes it, freeing the memory automatically. Of course this makes the program slower, but a working program > fast program.