HashMap memory usage

Posted on 2004-11-13
Last Modified: 2008-03-03

my program will do this:

- create HashMap a
- add mappings
- prune many mappings (maybe 80% or so)
- HashMap a will be stored as a property in Object b (b.hashMap)
- there will be many b objects.

I'm thinking that HashMap a might have much wasted space because of the objects that existed initially but are no longer there.

So I'm thinking about doing something like this (after pruning a):

- HashMap compactA = new HashMap(a)
- b.hashMap = compactA (instead of b.hashMap = a)

What do you think? Will this be more memory efficient? Or should I not bother?
Question by:ycomp
    LVL 13

    Accepted Solution

    b.hashMap = a;
    is better if all a is needed as it is, this will involve less memory operations
    LVL 92

    Assisted Solution

    I doubt you'll get much saving doing that (if any).

    Author Comment

    ok cool guys thanks.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
    In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now