Subj : Re: Multi-Thread and memory allocation error (or bug in 5.02). To : borland.public.cpp.borlandcpp From : "Ed Mulroy [TeamB]" Date : Fri Aug 29 2003 05:49 pm I see nothing obviously wrong in the code and give no guarantees as to if my ideas will solve the problem. I also found the code did generated no problem under BCB6 (XP Pro, 512M, PIII Mobile). I assume that by this: > If the creation and termination of the threads > removed the example runs fine. you mean that you still did the allocation and de-allocation of the arrays. If not then the test without threads didn't proove much since the code which the OS complains of does not execute. If it were my code, I try a couple of things. Increase the stack size to something like 16384, comment out creation of all but 2 of the 9 image lists (list2 through list7, list8 is already commented out) and put in code to check the return values from _beginthreadNT and SetThreadPriority. If I were getting very frustrated I'd probably also code to detect if WaitForSingleObject(mThread, INFINITE); returned WAIT_ABANDONED. Obviously some of the changes I mentioned may be difficult for the production code. My goal in suggesting this is to find the problem or at least generate a symptom related to a change so that the problem source can be identified. The RTL has undergone many changes in the 6 years since BC++ 5.02 was new. If it still does not yield to debugging then I suggest you try one of these two things. (Note that I've not used BC++ 5.02 for anything multi-threaded in years, so consider the source.) Set up a main thread (main program thread) delete function. Call that routine with the address of the int** array from the class. Let that function do the array deletion of the int** array and the int* arrays it contains instead of deleting in the destructor. Somehow arrange for a slight delay between when the thread ends and the deletion. or Create a class which is essentially a container for the int** array and the int* arrays it contains. That class should do the allocation and deletion. Use an auto_pointer of that class as a member variable in the TVMImageList class. Or you might try both (but of course not together). I am curious. Why do you do this: for (int j=0; j < mLength ; j++){ array = thearray[j]; delete[] array; } Instead of this: for (int j=0; j < mLength ; j++) delete[] thearray[j]; .. Ed > Martin Catney wrote in message > news:3f4f7adf$1@newsgroups.borland.com... > > I am experience some problems with Borland 5.02 with > multitheads and memory allocation and deallocation. > The same code on Borland Builder 6 appears to work > fine. I have included an example program which creates > multiple instances of the same class then deletes them. > The class constructor creates a new thread and allocates > a large block of memory while the destructor > deallocates the memory and terminates the thread. > > I get an access violation at 0x634b5e: read of address > 0x4cdc058 when I run the example. This corresponds to > the line delete[] array; in the class destructor. If the > creation and termination of the threads is removed the > example runs fine. > > Does anyone spot an obvious error in my example or is this a bug in the > Run-Time Library? .