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

  • SEARCH
  • Home
  • 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 682313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:34:54+00:00 2026-05-14T01:34:54+00:00

I know this may be a dumb question, but my background is more in

  • 0

I know this may be a dumb question, but my background is more in c++ and managing my own memory.

I am currently cutting down every single allocation that I can from one of my games to try and reduce the frequency of garbage collection and perceived “lag”, so for every variable that I create that is an Object (String and Rect for example) I am making sure that I create it before hand in my constructor and not create temporary variables in simple 10
line functions… (I hope that makes sense)

Anyways I was working though it some more tonight and I realized that I may be completely wrong about my assumption on garbage collection and primitive types (int, boolean, float) are these primitive type variables that I create in a 10 line function that gets called 20
times a second adding to my problem of garbage collection?

So a year ago every few seconds I would see a message in logcat like

GC freed 4010 objects / 484064 bytes in
101ms

Now I see that message every 15-90 seconds or so…

So to rephrase my question: Are primitive types (int, float, boolean, etc) included when seeing this message?

  • 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-14T01:34:55+00:00Added an answer on May 14, 2026 at 1:34 am

    Primitive types are not objects, so they do not cause any garbage collection. However, you do have to be very careful because due to boxing a primitive type can easily become an object without you explicitly doing so.

    For example, if you want a HashMap<> of integer keys, you would use HashMap. Note that because “int” is not an object, it can’t be used in a container. Integer is an object version of a primitive int. When you write code like this, an Integer object will automatically be created for you:

    HashMap<Integer, Object> map = new HashMap<Integer, Object>();
    int someNum = 12345;    // no object created.
    map.put(someNum, null); // Integer object created.
    

    Note that the exact same thing will happen if you don’t use generics, but even more hidden:

    HashMap map = new HashMap();
    int someNum = 12345;    // no object created.
    map.put(someNum, null); // Integer object created.
    

    For this particular situation, you can use Android’s SparseArray class, which is a container of primitive integer keys.

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

Sidebar

Related Questions

I know this may be simple question but want to know every ones opinion
This may seem like a dumb question, but still I don't know the answer.
I know this may sound like a dumb question but I got to know
This may seem like a dumb question but I don't know how to do
I know this may be a noob question, but it's bugging the heck out
I know this question may well be the silliest question you've heard today, but
Now this may seem like a silly question, but I need to know how
This may be a duplicate question, but really don't know how else to word
I know this is a total newbie question, but the answer may not be
I know this may be a stupid question to ask but I have really

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.