Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


ARC in Game Programming


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 aregee   Members   -  Reputation: 1061

Like
0Likes
Like

Posted 24 February 2014 - 10:20 AM

I am sorry if this belongs to "General Programming" instead of "Game Programming", but I was just thinking about something while watching my memory usage for my game go up, and up, and up...

 

It might be just me not fully grasping memory management yet, but I usually don't have much problems with excess memory usage in my general apps.  I had one situation where I had a 9GB file with intense string manipulation, where I had to terminate the program half way through because my program had reached 5GB RAM usage.  I just slapped in an @autorelease inside my tight loop, and the problem was solved.

 

I have a game I am making now that just eats more and more RAM.  I am guessing it is not really to blame ARC, rather me forgetting to release some resources or something, but I still wonder...

 

How is your stance on ARC in games.  How do you go about using (or not using) ARC in your games.  What are the reasons for your choices regarding ARC?

 



Sponsor:

#2 frob   Moderators   -  Reputation: 28707

Like
6Likes
Like

Posted 24 February 2014 - 12:27 PM

Looks like you are talking about Objective C's Automatic Reference Counting (ARC) garbage collection.


Garbage collection is a mixed blessing and curse.

When you are a beginner it really simplifies things; you can create an object and never worry about the rest of its lifetime. When you are writing small tools and short-running programs you don't have to think about memory management, it takes care of itself.

However, when your programs become more advanced, or when they are long-running, or when they are resource intensive like most modern games, resource management is very important. How important? When working on resource constrained systems like game consoles, mobile devices, embedded systems, and so on, or when you are working with very large data sets like your 9GB file on a desktop machine, I would say resource management is the most important factor in development; even if you introduce other bugs, don't mismanage the resources. You need to think about resource management continuously, and even a smallest error is likely to crash your system. Automatic garbage collection systems often hide or obscure that responsibility from programmers, making it so much easier to accidentally misuse it, hence the curse aspect. Using it properly is one of the biggest responsibilities of the programmer.

In most programs when you watch your resource usage "go up and up and up" like that, it means you have a bug in your resource management. Usually it means a resource leak. Usually it means your app will eventually slow down as it swaps to disk or crash suddenly when memory is exhausted. It is your responsibility to ensure resources are released in a timely manner so they can be reclaimed by the system.

Your next question, about my stance on garbage collections and choices regard it: It is something to be carefully monitored, like all other aspects of resource management. Several languages don't let you disable it, and many times it is a highly useful feature. It can be embraced, as long as you accept both the benefits and the responsibilities.

So in summary, yes, it does appear it is time for you to learn about proper resource management, including memory management, and end your blissful ignorance and reliance on automatic garbage collection. Programmers need to be responsible for the full object lifetime, even if that means a choice to clean resources up or let the GC do it, the programmers are ultimately responsible for the decision.

Edited by frob, 24 February 2014 - 12:33 PM.
Clarity.

Check out my book, Game Development with Unity, aimed at beginners who want to build fun games fast.

Also check out my personal website at bryanwagstaff.com, where I write about assorted stuff.


#3 aregee   Members   -  Reputation: 1061

Like
0Likes
Like

Posted 24 February 2014 - 02:28 PM

Thank you for your elaborate answer.  Yes, I am talking about Automatic Reference Counting in Objective C.

 

Given your answer, and my wish for portability, I think I have decided to move back to C++ for this particular project.  Again thanks for your answer.



#4 Buster2000   Members   -  Reputation: 2339

Like
0Likes
Like

Posted 25 February 2014 - 02:38 AM


Looks like you are talking about Objective C's Automatic Reference Counting (ARC) garbage collection.

 

There is no such thing.  ARC does not introduce garbage collection.  It is a compile time technology that statically analyses your code and then inserts the correct retains and release mechanisms to manage the life cycle of your objects.  There is no runtime process that manages the deallocation of objects due to ARC and because of this it cannot handle cyclic refferences in the way that garbage collection can.

 

The reason that your memory is going up and up is that somewhere in your program you have a "strong" refference to something that should be "weak".






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS