This topic is now archived and is closed to further replies.

do you need to free primitives in C

This topic is 5670 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Original post by Pfhorseti

The subject is kind of self-explanatory but do i need to manually free primitives in C?
if so, how would you do it?

Original post by Melraidin
Primitives like int, char, etc.? Not unless you dynamically allocate it. As long as you don''t do anything like int *pMyInt = new int;, you don''t have to.

Are we talking about C, or C++?

IMO, Melraidins answer is basically correct, but if we are talking about C, there is no such thing like "new" in C. In C you allocate dynamic memory with malloc() and deallocate it with free() .
If that was just a typo, and Pfhorseti meant C++, then you allocate with new and deallocate with delete , or allocate with malloc() and deallocate with free() .

In C++, malloc()/free() are considered deprecated and should be avoided when possible (AFAIK).

Forever trusting who we are
And nothing else matters
- Metallica

Share this post

Link to post
Share on other sites