This content has been marked as final. Show 3 replies
I am surprised you are just getting an OutOfMemoryError because are passing a 64K byte buffer you are trying to write 640*480*3 bytes = 900 KB from it. This means you are reading a random area of memory.
The logging messages will be using memory, so every time you execute this block I would expect the free memory to decrease.
jschell wrote:Yes, do that. The snippets provided are pretty useless.
java codeIf you think code is going to help then you need to post the actual code.
Could somebody tell me the reason for this?You are allocating something and then not freeing it. In your C code.
Probably calling malloc(), new, or something similar to get a buffer for GetByteArrayRegion(), then not freeing the buffer. Although I suppose it's possible that he's not calling DeleteLocalRef() on the passed-in byte buffer and that's preventing it from being GC'd. I've never really tried to figure out how that works or doesn't work.
And if all you're going to do is do one big write, don't use fopen/fwrite/fclose in append mode, just use open/lseek/write/close:
You don't want nor need the buffering that comes with fopen() et al when that's all you're doing.
int fd = open( filename, O_WRONLY ); lseek( fd, 0, SEEK_END ); write( fd, buffer, bytes ); close( fd );
And FWIW, you REALLY need to check return values from all of those, except maybe close() (what are you going to do if you can't close() it? Nothing, but maybe it's nice to know.)