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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:18:28+00:00 2026-06-18T17:18:28+00:00

I have a method 3 levels down in the call stack of an onDraw()

  • 0

I have a method 3 levels down in the call stack of an onDraw() method. It is called hundreds, sometimes thousands of times per redraw. I’ve done extensive profiling of the onDraw() method and I can see that the following method is taking 14% of the total so definitely worth looking at. I need to get my frame rates up during pinch zoom and drag operations.

private void getVisiblePointsFromPath(){

   double longRads = longitude * (Math.PI / 180);
   double latRads = latitude * (Math.PI / 180);

   ...

}

When the method exits and the doubles go out of scope, I assume that they become eligible for GC although I recognise when this might happen is non-deterministic.

Is there anything to gain by doing this:

public class GisView extends ImageView{

    private double longRads;
    private double latRads;

    private void getVisiblePointsFromPath(){

       longRads = longitude * (Math.PI / 180);
       latRads = latitude * (Math.PI / 180);

       ...

    }

}

I assume that this idiom will cause the doubles to be nulled then reassigned on each pass but will not result in additional garbage and thus reduce the amount of GC I’m causing. Or is the VM smarter than that?

Please note that my question is not “which is faster” per se, it’s about which is likely to lead to less GC. I can measure the speed difference but I don’t understand enough of the Dalvik VM and Android GC to predict which causes less garbage.

  • 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-06-18T17:18:29+00:00Added an answer on June 18, 2026 at 5:18 pm

    I assume that this idiom will cause the doubles to be nulled then reassigned on each pass but will not result in additional garbage and thus reduce the amount of GC I’m causing. Or is the VM smarter than that?

    Primitive local variables live on the stack, not the heap, so they don’t need to be GC’d at all. They are effectively gone as soon as the function returns – because that clears the stack frame.

    That said, yes, the doubles will be reassigned on each pass, because that’s what the code you’ve written says to do. If you want to increase the speed of this particular method, calculate longRads and latRads when longitude and latitude are set. The right way to do this is to always delegate setting those fields to a setter method. For example:

    public void setLongitude(double longitude) {
        this.longitude = longitude;
        this.longRags = longitude * (Math.PI / 180);
    }
    

    This will, of course, make setting a slower operation, but that’s not what you asked about optimizing.

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

Sidebar

Related Questions

I have a unit test (nUnit). Many layers down the call stack a method
I have a navigation based application using Core Data and several levels of drill-down
I have a object, let's call it Friend. This object has method GetFriendsOfFriend, that
On the class level, I have created reference: System::Data::Odbc::OdbcConnection Connection; in some method I
I have method that returns Drawable , and if its Bitmap object is recycled
I have method that returned NSManagedObject and I don't know what kind of NSManagedObject
I have method with two parameters: bool1 and bool2. Both are boolean of course.
I have method that returns module path of given class name def findModulePath(path, className):
I have method in a class that I need to make sure is only
I've got some 3rd party beans that have method signatures that fit quite well

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.