Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7558513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:23:23+00:00 2026-05-30T12:23:23+00:00

Im doing a memory analysis of an existing java software. Is there a sql

  • 0

Im doing a memory analysis of an existing java software. Is there a sql ‘group by’ equivalent in oql to see the count of objects with same values but different instances.

select count(*)
from java.lang.String s
group by s.toString()

I’d like to achieve a list of duplicated strings along with the number of duplicates. The purpose of this is to see the cases with large numbers so that they could be optimized using String.intern().

Example:

"foo"    100
"bar"    99
"lazy fox"    50

etc…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T12:23:25+00:00Added an answer on May 30, 2026 at 12:23 pm

    The following is based on the answer by Peter Dolberg and can be used in the VisualVM OQL Console:

    var counts={};
    var alreadyReturned={};
    
    filter(
      sort(
        map(heap.objects("java.lang.String"),
        function(heapString){
          if( ! counts[heapString.toString()]){
            counts[heapString.toString()] = 1;
          } else {
            counts[heapString.toString()] = counts[heapString.toString()] + 1;
          }
          return { string:heapString.toString(), count:counts[heapString.toString()]};
        }), 
        'lhs.count < rhs.count'),
      function(countObject) {
        if( ! alreadyReturned[countObject.string]){
          alreadyReturned[countObject.string] = true;
          return true;
        } else {
          return false;
        }
       }
      );
    

    It starts by using a map() call over all String instances and for each String creating or updating an object in the counts array. Each object has a string and a count field.

    The resulting array will contain one entry for each String instance, each having a count value one larger than the previous entry for the same String.
    The result is then sorted on the count field and the result looks something like this:

    {
    count = 1028.0,
    string = *null*
    }
    
    {
    count = 1027.0,
    string = *null*
    }
    
    {
    count = 1026.0,
    string = *null*
    }
    
    ...
    

    (in my test the String "*null*" was the most common).

    The last step is to filter this using a function that returns true for the first occurrence of each String. It uses the alreadyReturned array to keep track of which Strings have already been included.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing memory-mapped IO in Java. The FileChannel class allows you to map a
So I am doing some memory analysis on a windows memory image and I
We are using DevPartners boundchecker for detecting memory leak issues. It is doing a
Hey all. I'm doing a linked list exercise that involves dynamic memory allocation, pointers,
While developing for iphone i get EXC_BAD_ACCESS when doing sqlite3 *memory_db; if (sqlite3_open(:memory:, &memory_db)
Can't think of a neat way of doing this in java: I'm streaming sets
I was doing a memory profile in Instruments for my iPhone app and I
When using malloc and doing similar memory manipulation can I rely on sizeof( char
I am doing memory leak testing. The tool indicates a leak in line 2
I've read apple documentation to assert that I was doing the memory management correctly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.