Q:

C, Xcode and memory

Why after executing next C-code Xcode shows 20KB more than it was?
void *p = malloc(sizeof(int)*1000);
free(p);

Do I have to free the memory another way? Or it's just an Xcode mistake?

A:

When you say "Xcode shows 20KB more than it was", I presume you mean that the little bar graph goes up by 20kB.  
When you malloc an object, the C library first checks the process's address space to see if there is enough free space to satisfy the request.  If there isn't enough memory, it goes to the operating system to ask for more virtual memory to be allocated to the process.  The graph in Xcode measures the amount of virtual memory the process has.
When you free an object, the memory is never returned to the operating system, rather, it is "just" placed on the list of free blocks for malloc to reuse. I put the word "just" in scare quotes because the actual algorithm can be quite complex, in order to minimise fragmentation of the heap  and the time taken to malloc and free blocks.  The reason memory is never returned to the operating system is that it is very expensive to do system calls to the OS to get and free memory. 
Thus, you will never see the memory usage of the process go down.  If you malloc a Gigabyte of memory and then free it, the process will still appear to be using a Gigabyte of virtual memory.
If you want to see if your program really leaks, you need to use the leaks profile tool.  This intercepts malloc and free calls so it knows which blocks are still nominally in use and which have been freed.

