Please help me understand this memory problem

Symptoms:
1. it claims more and more of the working memory
2. after some (seemingly random) time it crashes with exception code c0000005 (access violation)

First I thought it might be a memory leak, but I can't find anything. Now I wonder if the problem may be caused by the number of threads.

My program starts a new std::thread for each message that it receives. The thread is detached directly after it is started, I did this because they can just disappear at any time they are done with processing the message and I did not know a way to store handles to a dynamically changing number of threads.
Because the threads are detached, the resources they use should automatically be released when the thread is done.

So I wonder if the number of threads may be a cause for my memory problem. Could anyone tell me:
- How much memory is reserved for each thread (do they go on the stack or heap)?
- Is there a way to check how much of this memory is still available?
- Is there a way to check how many threads are still running after the threads have been detached?

Does anyone here have any other suggestions on how to overcome this issue? Thanks in advance.
Last edited on
I still have the same problem, but now I realized it might not be a memory leak. Instead the program might just be using a lot more memory than I had expected, possibly because the threads exist for longer than I had expected (what would result in more simultaneous threads).

Is there any way to get data about this?
I am not sure ... but i get confused about that:

and I did not know a way to store handles to a dynamically changing number of threads

Is that not possible? I think you can use a vector or a map to store the handles ... that would work easily with a map i think.

Also, i am not sure, if an access violation should be the result of using too much memory ...
you can see memory usage in the task-manager, so you determine if the application really consumes all your RAM.
In addition, if that happens, some allocation will fail, and i would bet for a "malloc" that fails because of "NO MEMORY", just returning NULL ("new" throws exceptions ...) or something simmilar ... don't know, maybe you should handle that out_of_memory case in your code and terminate the application if such a thing happend ...

Mybe you don't use "malloc" fcns ... then i have no idea, how an access violation can happen ... it should be some "bad_alloc" exception or, well ... i don't know.

Hope that helps you,
,....


Topic archived. No new replies allowed.