For java portlets/ servlets are there any good tool to test and detect if code is written without allocate an extensive amount of memory?

Obviously there is a garbish collector that kicks in. Sooner or later the garbish collector will have to deallocate all that memory and that will cause CPU usage.