In the docs it mentions that any memory allocated with AllocateMemory will be freed when the program ends. Of course instead we'll use FreeMemory when done with buffer. But I'm having some problems with AllocateMemory, pointers, and threads, all tangled together. Question:
If a procedure is launched as a new thread (CreateThread), and in that procedure AllocateMemory is used to create a buffer, and then the procedure (and thread) ends, is the buffer still allocated? Or was the memory released by PB when the thread ended?
Threads and AllocateMemory
- NicTheQuick
- Addict
- Posts: 1226
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
Re: Threads and AllocateMemory
The memory is still allocated because it is the same process. You can use the same memory block in different threads.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
- RichAlgeni
- Addict
- Posts: 914
- Joined: Wed Sep 22, 2010 1:50 am
- Location: Bradenton, FL
Re: Threads and AllocateMemory
Unless you use FreeMemory(), the memory is not released until the program ends. You can use that memory in different threads, as long as you keep the reference to it. If you lose the reference to the memory when you close a thread, the memory will still be allocated, but it will be unusable. The same goes with opening a file, or a database handle. These would all be called memory leaks.