Subj : Re: Problems with delete/free To : borland.public.cpp.borlandcpp From : "Ed Mulroy [TeamB]" Date : Mon Oct 27 2003 04:38 pm > /* free memory */ > free(str); > > printf("String is %s\n", str); ^^^^^^ Wrong. You just freed the memory whose address is contained in 'str'. That memory is no longer valid. > > //----------------------------- > > str1 = new char(30); //(char *) malloc(30); Wrong. That allocated ONE char with an initial value of decimal 30 (the same as '\x1E'). To allocate an array of 20 elements, show it as an array like this: str1 = new char[30]; > delete str1; //free(str1); Wrong. You are freeing an array. The correct syntax is: delete [] str1; I do not guarantee that there are not other problems in that program. Those are the ones which were apparent. .. Ed > Rob C wrote in message > news:3f9d8505$1@newsgroups.borland.com... > > This is very strange. I wrote a program to test new/delete - > malloc/free functions. Both sets worked fine as long as > I “compiled” the program as a single module. When I built them > as a project, however, free and delete wouldn’t do > anything . . . no errors or warnings or anything, but they just > wouldn’t do anything. I tried all the platforms, but still they > just wouldn’t do anything. What’s going on? > --------------------------------------------------- .