IntelliJ Memory Leak Detection

Finding and fixing Spring Data JPA performance issues with FusionReactor
How to Find Memory Leaks in Your Application

IntelliJ Memory Leak Detection

IntelliJ is a pioneer development kit among JetBrains extended lineage of integrated development environments (IDE). This trailblazer IDE formerly shared the same name with the parent company – IntelliJ Software Company. To illustrate further the superiority of the IntelliJ IDE, it powers and supports over a dozen programming languages, including; Java, Groovy, Kotlin, Ruby, Python, PHP, C, Objective-C, C++, C#, Go,[9] JavaScript and SQL.

Also referred to as IntelliJ IDEA, this IDE is a comprehensive and handy tool for programming, debugging, and profiling. Therefore, learning how to detect memory leaks in a powerful development environment such as IntelliJ is of utmost importance. Although IntelliJ comes with an inbuilt profiling functionality, the use of certain dedicated and multi-purpose profilers such as FusionReactor would be pretty slick.

How to Find Memory Leaks in IntelliJ IDEA

A robust memory detection tool can efficiently analyze and detect java heap leaks while optimizing memory usage on the fly. Nonetheless, this is a primer exclusive to monitoring and reviewing the conditions that induce object retention, which is very useful information to keep in mind when detecting leaks. Another special procedure would be to evaluate the memory usage, to better understand your application’s inner workings and minimize the creation of redundant objects.

Steps taken for IntelliJ Memory Leak Detection

Firstly, we need to display the Memory tab by clicking on the window icon in the top-right corner of the Debug tool window.

The Memory tab would display the following information as follows;

The Class: – which is the name of the Class in use.
The Count: – a number indicating the number of class instances (objects) present in the heap.
The Diff: – this represents the discrepancy between the number of instances in two execution points.

IntelliJ Memory Leak Detection, FusionReactor

Figure 1: The Memory Tab.

Next, we would need to fetch the information regarding the number of objects present. To do this, we would have to;
Manually pause the program or halt at a certain breakpoint.
Then, we would have to initiate the procedure by selecting Load Classes on the Memory tab settings icon. While the list of loaded Classes is displayed on the Memory tab, the corresponding number of active objects is shown in the Count column.

Note that this process is only initiated on-demand for performance reasons.

Our next task would be to find and sort these Classes. Finding a Class, is as easy as typing the class name in the search bar provided. To sort these Classes, click

Click on any of the headers that correspond to what you want from the option – Class, Count, or Diff. By clicking on the already selected criterion changes, you automatically change the format of the order – to either ascending or descending.

Next up is to get the difference between two execution points by means of the Diff column as described above. In order to achieve this, we would have to set up two points – which we would refer to as the starting and second point throughout the scope of this guide.
Collect the instance data at the starting point.

IntelliJ Memory Leak Detection, FusionReactor

Figure 2: Collecting instance data at start point.

Resume program execution.

IntelliJ Memory Leak Detection, FusionReactor

Figure 3: Stepping through the code.

Fetch the instance data from the second point by looking at the Diff column, we could ascertain the changes in the number of instances in real time.

IntelliJ Memory Leak Detection, FusionReactor

Figure 4: Checking for changes in the number of instances.

Once we double click on a Class in the Memory tab to view its instances, a dialog box pops on, indicating all live instances of that Class. At this juncture, we could filter the list using conditions, while exploring the contents of each object.

For instance, in order to propagate a list of all objects with an empty String, we would have to double-click String on the Memory tab and key in the following condition; this.isEmpty() in the Condition field.

IntelliJ Memory Leak Detection, FusionReactor

Figure 5: Viewing Instances.

Now the have to keep track of these instances. Additionally, we can view the number of instances and also record the creation of every instance along with its location in the call stack. For this, we would have to
Right-click on that Class and select Track New Instances. Upon initiating this process, the Memory tab would store and all information on every instance of that Class, from that moment onwards. If there are new instances their number would be displayed in parenthesis in the Diff column.

IntelliJ Memory Leak Detection, FusionReactor

Figure 6: Tracking Instances.

To navigate the contents of each object, view the list of new instances and see the stack trace, click on the number in the Diff column.

Note that, for the Memory tab to track instances, it has to be kept open at all times.

The final step would be to customize the view and thus, the modus operandi of the Memory tab. Now there are a number of options available for this. These settings could be toggled from the Memory View Settings icon.
Show with Instances Only option lets you to only display Classes with live instances.
Show Non-Zero Diff Only option filters objects with a varying total number between the starting and second point.
Show tracked classes only option allows you to only view classes whose new instances you are tracking.
Enable Tracking with Hidden Memory View option permits you access track new instances of selected Classes even when they are hidden.
Update Loaded Classes on Debugger Stop option lets you to auto-load Classes and collect data even when the program is suspended.

Note that, the last two options may likely add extra overhead to the debugged application and thus impact stepping performance.

IntelliJ Memory Leak Detection using FusionReactor

One effective way to detect memory leaks in IntelliJ is using a tool called FusionReactor. FusionReactor is a real-time performance monitoring tool that can help you identify and fix memory leaks in your Java applications.

The process of IntelliJ memory leak detection using FusionReactor would primarily use the following features of FusionReactor:

  1. Real-time performance monitoring: FusionReactor provides real-time monitoring of the memory usage, CPU utilization, and other performance metrics of your Java application, including IntelliJ.
  2. Memory analysis: The memory analysis feature of FusionReactor provides detailed information about the memory usage of your Java application, including heap size, object references, and memory leaks.
  3. Snapshots: The snapshots feature of FusionReactor allows you to take a snapshot of the memory usage of your Java application at any point in time. This can be useful for identifying memory leaks and analyzing memory usage trends over time.
  4. Memory Analyzer: The Memory Analyzer feature of FusionReactor provides a graphical representation of the memory usage of your Java application, including object references, memory usage, and potential memory leaks.
  5. Alerts and notifications: FusionReactor provides alerts and notifications when memory usage exceeds a specified threshold, allowing you to address potential memory leaks before they become major issues proactively.

By using these features of FusionReactor, you can effectively detect and resolve memory leaks in your IntelliJ application, helping to ensure its performance and stability.

Steps to set up FusionReactor for IntelliJ memory leak detection:

  1. Install FusionReactor: Download and install FusionReactor from the official website.
  2. Start IntelliJ with FusionReactor: Start IntelliJ from the command line using the following command: “fusionreactor -jar <path_to_IntelliJ_executable>”. This will start IntelliJ with FusionReactor, allowing you to monitor its performance.
  3. Configure FusionReactor: In FusionReactor, go to the “Settings” tab and configure the settings according to your requirements. For example, you can set the sampling rate, memory usage threshold, and other parameters.
  4. Monitor memory usage: In the “Dashboard” tab, you can monitor the memory usage of your IntelliJ application in real time. You can also use the “Snapshots” tab to take a snapshot of the memory usage and identify any potential memory leaks.
  5. Fix memory leaks: If you identify a memory leak, you can use the “Memory Analyzer” tab to drill down into the cause of the problem. You can view the object references, memory usage, and other details to help you identify and fix the memory leak.

By using FusionReactor for IntelliJ memory leak detection, you can ensure that your Java applications run smoothly and efficiently, even as they grow and evolve over time.

Recent Posts