Memory tracking

VisualVM can be used to monitor memory allocations and detect possible memory leaks. Let's modify our application to simulate a large memory allocation that has not been released. We will modify the CourseService class:

public class CourseService { private CourseDAO courseDAO = new CourseDAO(); //Dummy cached data used only to simulate large //memory allocation private byte[] cachedData = null; public synchronized List<CourseDTO> getCourses() { //To simulate large memory allocation, //let's assume we are reading serialized cached data //and storing it in the cachedData member try { this.cachedData = generateDummyCachedData(); } catch (IOException e) { //ignore } return courseDAO.getCourses(); } private byte[] generateDummyCachedData() ...

Get Java EE 8 Development with Eclipse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.