Backbase Interview Question

Explain how garbage collector works and how would you do memory profiling for java application.