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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:08:34+00:00 2026-05-30T18:08:34+00:00

Let’s say I’m iterating over an array of Objects i.e. for (int r =

  • 0

Let’s say I’m iterating over an array of Objects i.e.

for (int r = 0; r < rows; r++) {
        for (int c = 0; c < columns; c++) {

            if (bricks[r][c] != null) {
                bricks[r][c].draw(gl)

If I at some point want to destroy the brick, should my remove() method nullify the object like :

private void remove(GameBrick obj) {
     for (int r = 0; r < rows; r++) {
        for (int c = 0; c < columns; c++) {
        if (bricks[r][c] != null){
        if (bricks[r][c] == obj) {
            bricks[r][c] = null;
        } 

Or should it rather set a flag boolean exists to false, and while iterating the objects, add a return or continue statement if bricks[r][c].exists == false ?

Currently I have my code based around nullifying object and null checks, but I later read about the Garbage Collector and that setting an object to null makes it run more often.

I want to know if this is true, and what I should do best to remove objects (if I even should).

  • 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-30T18:08:35+00:00Added an answer on May 30, 2026 at 6:08 pm

    but I later read about the Garbage Collector and that setting an
    object to null makes it run more often.

    Nope, that would be pure hearsay. The best approach is to assume that the GC has been optimised to run as often as necessary to get the best balance between performance and memory usage.

    Setting references to null is the way you signal to the GC that you no longer need the object. the GC doesn’t have to do anything about it immediately.

    Update

    To tune the performance of an application, you have to measure the behaviour of the whole application – which means you have to write the whole application (or a very realistic end-to-end model of it) first. Micro-optimisation doesn’t work.

    So the best approach is to let the GC do what it is designed for – to make it easy for you to write clear, simple, easy-to-modify code thanks to automatic memory management. That way, when you have tested your app on the target machine/device and you can see where you need to tune performance, it will be easy to make the necessary changes without breaking anything.

    Performance optimisation has to be driven by measurement. Measurement has to be done on a realistic prototype of the complete product. So in your first-pass implementation, concentrate on writing easy-to-modify code. Then measure, and put messy hacks into only the places where they are actually needed.

    Bear in mind that they may need to be in different places depending on the device you are running on! On some devices, a hack applied in a specific spot may slow you down, whereas on another device it speeds you up. So you can’t just blindly follow a rule everywhere in your code. You have to measure.

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

Sidebar

Related Questions

Let's say there is a graph and some set of functions like: create-node ::
Let's say I have the string: hello world; some random text; foo; How could
Let say I have some code HTML code: <ul> <li> <h1>Title 1</h1> <p>Text 1</p>
Let's say I have a javascript array with a bunch of elements (anywhere from
Let's say I wanted all nodes whose parent(s) matched some certain condition. Is there
Let's say i have this block of code, <div id=id1> This is some text
Let's say I want to have some kind of a cache that did something
Let's say you create a wizard in an HTML form. One button goes back,
Let's say I'm building a data access layer for an application. Typically I have
Let's say you have a class called Customer, which contains the following fields: UserName

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.