Leak caused by fread
Posted
by
Jack
on Stack Overflow
See other posts from Stack Overflow
or by Jack
Published on 2012-04-14T17:19:35Z
Indexed on
2012/04/14
17:29 UTC
Read the original article
Hit count: 256
c++
I'm profiling code of a game I wrote and I'm wondering how it is possible that the following snippet causes an heap increase of 4kb (I'm profiling with Heapshot Analysis of Xcode) every time it is executed:
u8 WorldManager::versionOfMap(FILE *file)
{
char magic[4];
u8 version;
fread(magic, 4, 1, file); <-- this is the line
fread(&version,1,1,file);
fseek(file, 0, SEEK_SET);
return version;
}
According to the profiler the highlighted line allocates 4.00Kb of memory with a malloc
every time the function is called, memory which is never released. This thing seems to happen with other calls to fread
around the code, but this was the most eclatant one.
Is there anything trivial I'm missing? Is it something internal I shouldn't care about?
Just as a note: I'm profiling it on an iPhone and it's compiled as release (-O2
).
© Stack Overflow or respective owner