![]() The garbage collection routines in Java are highly optimized, and if you learn how their algorithms work, you can make sure your program behaves in the optimal way for those algorithms to work. What you should focus on is what in in your control, which is making sure you don't hold on to references longer than you need to, and that you are not duplicating things unnecessarily. What you are concerned about you can't control, not directly anyway The JDBC driver did lots and lots of String manipulation, kind of the trade off of using PreparedStatements for everything. Once when profiling CPU usage on a web app that also had an Oracle JDBC dependency I discovered that StringBuffer.append() dominated the CPU cycles by many orders of magnitude over all other method calls combined, much less any other single method call. This isn't just a Java thing, String data types take up lots of memory in pretty much every language and run time library, because at the least they are just arrays of 1 byte per character or at the worse ( Unicode ) they are arrays of multiple bytes per character. Just because they are so fundamental to most business applications as a data type, and they are one of the most memory hungry as well. How they are created determines how much memory they consume in the JVM. Currently it returns generic information such as string or int but I want to know which object its referring to so I can work on getting its size more optimized.īasically in Java, String references ( things that use char behind the scenes ) will dominate most business applications memory wise. Is there a easy way to do this? I right now I am using eclipse and java to develop(and installed visualVM and netbeans specifically for profiling but am willing to install anything else that you feel gets this job done).ĮDIT: Ideally, I'm looking for something that will take all my objects and sort them by size(so I can see which one is hogging memory). My problem is I don't know how to read them, I got the highest area just saying char and I can't see any code or anything(which makes sense because visualvm is connecting to the jvm and can't see my source, but netbeans also does not show me the source as it does when doing cpu profiling).īasically what I want to know is which variable(and hopefully more details like in which method) all the memory is being used so I can focus on working there. So here's what I did, I added a break point to the start of my program and ran it, then I started visualVM and had it profile the memory(I also did the same thing in netbeans just to compare the results and they are the same). I have a program that is taking a ton of memory and I want to figure a way to reduce its usage, but after reading many SO questions I have the idea that I need to prove where the problem is before I start optimizing it. I'm still learning the ropes of Java so sorry if there's a obvious answer to this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |