www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Memory leak in zlib with void[]

reply Ald Sannes <aldarri_s yahoo.com> writes:
Hello.
I have the following code:

		int zipFileSize = getSize(fileName);
		
		void[] zipFileContent = uncompress(read(fileName), 0, 24);
		
		delete zipFileContent;
				
		return cast (char []) zipFileContent;

I am unzipping some 50 Mbytes of data, and some 50 Mbytes are not being freed.

The delete statement was added to check for memory leaks, and it is there to
check is memory leak.

The program does nothing else (commented out).

Where to free the memory?
Nov 09 2007
parent reply torhu <no spam.invalid> writes:
Ald Sannes wrote:
 Hello.
 I have the following code:
 
 		int zipFileSize = getSize(fileName);
 		
 		void[] zipFileContent = uncompress(read(fileName), 0, 24);
 		
 		delete zipFileContent;
 				
 		return cast (char []) zipFileContent;
 
 I am unzipping some 50 Mbytes of data, and some 50 Mbytes are not being freed.
 
 The delete statement was added to check for memory leaks, and it is there to
check is memory leak.
 
 The program does nothing else (commented out).
 
 Where to free the memory?
You can't free zipFileContent, and then use it afterwards. Free it when you don't need it anymore. You might also want to look at std.zip, which is higher level than std.zlib.
Nov 09 2007
parent Ald Sannes <aldarri_s yahoo.com> writes:
torhu Wrote:

 Ald Sannes wrote:
 Hello.
 I have the following code:
 
 		int zipFileSize = getSize(fileName);
 		
 		void[] zipFileContent = uncompress(read(fileName), 0, 24);
 		
 		delete zipFileContent;
 				
 		return cast (char []) zipFileContent;
 
 I am unzipping some 50 Mbytes of data, and some 50 Mbytes are not being freed.
 
 The delete statement was added to check for memory leaks, and it is there to
check is memory leak.
 
 The program does nothing else (commented out).
 
 Where to free the memory?
You can't free zipFileContent, and then use it afterwards. Free it when you don't need it anymore. You might also want to look at std.zip, which is higher level than std.zlib.
And who exactly is going to stop me? Seriously, I know that it is nullified during the deletion operation, but the complaint is that memory still leaks. Am also extremely unhappy to report that using char[][] wordList = std.regexp.split(line, " |>|[.]|,|/|\\|\\*", "g"); may leak up to a Gb of memory. That is 2^30 bytes. I remember a discussion a while ago about the GC not freeing arrays after concatenation, and that it was fix. Perhaps that has something to do with it?
Nov 09 2007