Why do I have to use free() when I declare a pointer such as:
int *temp = (int*)malloc(sizeof(int))
*temp = 3;
but not when I do:
Because the language let's you pick between the stack and the heap.
Reasons why you'd want to pick between the stack and the heap:
Why the heap can't be automatically freed:
Because there is no way to know when you are done with the memory. There are ways to emulate garbage collection, but this involves when you have no more variables on the stack and heap holding a pointer to the data on the heap.
More on Stack vs Heap:
The C language let's you chose whether you want to define your variables on the stack or the heap.
malloc create variables on the heap. A simple declaration such as int x; creates a variable on the stack.
See further reading on stack vs heap in my answer here.
Pointers:
Just to clarify: Pointer varaibles are created on the stack and they hold a memory address to the data allocated on the heap. They take 4 bytes on the stack on a 32-bit system and 8 bytes on the stack on a 64-bit system.