Does exiting from a pthread release malloced memory?

Threads share memory resources (at least POSIX) malloc() / realloc() / free() memory management is not actually aware about threads (at least by now) So you should treat results of malloc() as simple 'resource'. It is not thread-linked So now answer should be obvious, any memory allocated has no linkage to threads so it is not free()'d on thread exit. Of course you can provide some special handling mechanics but it is not done automatically Good side of this is you can pass memory allocation between threads in other words allocate such resource in one thread and then free from another (is it good for you or not) Hope this would be useful explanation, think about allocated memory pointer as about any process-level descriptor.

Threads share memory resources (at least POSIX). Malloc() / realloc() / free() memory management is not actually aware about threads (at least by now). So you should treat results of malloc() as simple 'resource'.

It is not thread-linked. So now answer should be obvious, any memory allocated has no linkage to threads so it is not free()'d on thread exit. Of course you can provide some special handling mechanics but it is not done automatically.

Good side of this is you can pass memory allocation between threads in other words allocate such resource in one thread and then free from another (is it good for you or not). Hope this would be useful explanation, think about allocated memory pointer as about any process-level descriptor.

No - malloc'ed memory is only ever freed by an explicit 'free'.

1 Or when the whole process exits - atleast on your typical desktop/server OS. – nos Nov 6 '09 at 19:54.

I'm pretty sure it doesnt, you have to use free().

No. While any malloced memory is freed when the process exits, this same is not true for when the thread exits.

Good side of this is you can pass memory allocation between threads in other words allocate such resource in one thread and then free from another (is it good for you or not). Hope this would be useful explanation, think about allocated memory pointer as about any process-level descriptor.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions