Hacker News new | ask | show | jobs
by windowojji 1959 days ago
Does C have destructors?
1 comments

Only if you make it and call it.

C has free, which deallocates a block of memory pointed to by a pointer. If it's a struct, the struct is deallocated. If the struct contains pointers, that memory is still there. If you've lose all the pointers to that chunk of memory, you now have a memory leak.

It is not uncommon to make your own allocators and deallocaters for complex structs.