The kernel has a collection of process records within the kernel's memory and keeps track of each process, the amount of memory consumed, resources such as i/o, file handles or inodes. The process records are usually held in a queue in which the kernel's task pointer points to the process record in a never ending fashion (that explains why the perception of 'multi-tasking', it is doing that a blink of an eye - so fast, really, it is doing single tasking in the eyes of the kernel). There is a field in the process record that tells how much memory is chewed up by said process.
Yes the kernel does obtain the memory back to its own pool ready for consumption by another process. Furthermore, you are absolutely 100% correct in relation to memory leaks as John Weldon above pointed out. I mentioned this in another posting, for every malloc there is a free, if there isn't you have a memory leak. So don't worry about your debugging session. That is perfectly ok as the kernel has a responsibility to ensure the memory is reclaimed.
Some applications (especially daemons) must be debugged throughly and that no memory leaks occur in it as the daemon will be running for a long time before the next reboot. Incidentally, it was mentioned in my favourite book 'Expert C Programming, Deep C Secrets - Peter Van Der Linden', that at one stage when he was in Sun, there was a tool called 'printtool' for printing, but every so often the queue jammed up because there was a memory leak in the print spooler program and the reboot of the Sun machine cured it, he describes that in detail in relation to memory leaks.
Hope this helps,
Best regards,
Tom.