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 6130417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:51:22+00:00 2026-05-23T16:51:22+00:00

I am trying to make a game for android I have a bitmap and

  • 0

I am trying to make a game for android
I have a bitmap and canvas instance in my main class.

I have another instance of, lets say, renderer class.
That renderer class is in the same package, but not the subclass of my main class.

If i pass the bitmap and canvas instance to a method of that renderer class and that method will draw that passed bitmap to the passed canvas, are the actual instances passed or new instance copies created and then passed ? Well, i have tried and saw that actual instances were being passed. Because i was seeing the bitmap being drawn to the canvas.

Here is my question, why are the actual instances are passed ?
if it was something like this ->


public class instanceTest
{
    static int num;

    static void numIncrementor(int number)
    {
        number++;
    }

    public static void main(String[] args)
    {
        num = 0;
        numIncrementor(num);
        System.out.println(num);
    }
}

Here, when i print the num, i will still get 0, but with other bitmap and canvas thing, i do send the actual instances. This got me really confused. Can someone explain it ?
Or is it always the case with class objects unlike primitive types ? Does it make garbage collector go crazy ?

Thanks in advance, if you did not understand my engrish, tell and i will put pseudo codes here for clarification;

  • 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-23T16:51:22+00:00Added an answer on May 23, 2026 at 4:51 pm

    You should really read the Java tutorial before starting to write Java code.

    In your example above you passed a primitive – so it’s value is simply passed to the method, placed on the stack and that value is altered. That is how primitives work in Java. This means that your number variable only exists within the scope of the numIncrementor method – and does not effect what is outside.

    Your actual code works with objects. When you pass an object you actually pass the reference to it on the heap. So every change you do to it will be done on the actual object. The only exception is that you cannot “re-assign” the object to something else since you only hold a reference to the heap – you can “re-assign” your reference to another location on the heap, but the original reference will continue to point to the original object.

    As for your question on the garbage collector – no, it will not go crazy. It actually works pretty good. (There is more than one type of GC, but that is a whole different discussion).

    Java does not use Copy Constructors – if you want to pass a copy of an object to a method, you should make it cloneable and pass a clone of it. But this is probably not what you need – note that Copy Constructors consume more resources than just passing the reference to the object.

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

Sidebar

Related Questions

I am trying to make burning star impression on android game I have been
If you were to make a simple game, lets say a stick figure that
I'm, trying to make a simple 3D game for Android, and I want to
I have been trying to make a Cross-platform 2D Online Game, and my maps
I'm trying to make a dictionary game, and I have a text file with
I'm trying to compile (make) a game source and it seems that my gRace.cpp
I have just started trying to make a simple game with XNA 3.1 to
I am trying to make a game for android. It is based on a
I'm trying to make a tetris game for android to help learn game programming
i am trying to make some kind of reflex like game for android, which

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.