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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:10:44+00:00 2026-05-24T18:10:44+00:00

I am programming a type of game in C# and I want to know

  • 0

I am programming a type of game in C# and I want to know what would be a better approach for memory usage. Right now I have it so it goes through a while loop and while the game is running it will check for certain things (is this person dead, etc), sleep for one second, then try again. Once the game is over the while is set to false and it exits the method. Would a timer be a better way of doing this? I’m noticing memory issues sometimes when I run this game.

  • 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-24T18:10:45+00:00Added an answer on May 24, 2026 at 6:10 pm

    The while loop approach is probably not your problem. Timer is in fact a bit heavier than this approach, and will consume more system resources, but this will be a one-time allocation. In other words, changing your main loop code from one structure to the other is unlikely to change your application’s memory profile significantly.

    Have you tried profiling your application’s memory usage? You’re likely holding on to objects that you don’t need anymore. A profiler might be able to help you determine where.

    (In case you are curious, using a Timer will likely have a very small performance impact, since each iteration will cause a function pointer call, which the CPU and JIT-compiler cannot optimize very well. Using a while loop means that your code is always running; the Thread.Sleep() call can be optimized fairly well since it is not through a function pointer. Considering that the Timer approach is also likely to result in less readable code, I would strongly suggest that you continue using a while loop.)

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

Sidebar

Related Questions

I am programming in .NET I have an application setting of type string. On
Programming language: Java Ok, so I want to have a BufferedImage that keeps rotating
I'm programming on a Android Game that includes the jDroidlib library. And I want
I have heard the term universal type thrown around in the context of programming
I have been programming for about 3 years now and feel confident in my
I have a weird issue whereby I'm programming a carousel-type animation in jQuery. I
I'm fairly decent in php programming and I know this type of error means
I have been using the Gloss Library for some game programming, and have got
I have a basic install of Sharepoint running, and the first programming type task
Trying to get better at programming. Working on building a silly game to teach

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.