Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak on Android when Orientation Changes #170

Closed
dellis1972 opened this issue Dec 14, 2011 · 4 comments
Closed

Memory Leak on Android when Orientation Changes #170

dellis1972 opened this issue Dec 14, 2011 · 4 comments

Comments

@dellis1972
Copy link
Contributor

There seems to be a big problem with the Orientation change stuff on Android. After reading the documentation the Activity is re-created each time the Orientation/Configuration changes. The means the Game object is being re-created each time, so all the assets are loaded again and again and again each time the orientation changes.

We need to figure out a way to detect this and keep the same game object/ content manager around and just swap out the Activity/ AndroidGameView.

This will not effect people who just use a fixed screen orientation for games as the orientation will not change. however this might be the cause of the Resume issue we have been seeing as well.

@dellis1972
Copy link
Contributor Author

@KonajuGames
Copy link
Contributor

Use the following attribute to prevent the activity being recreated on an
orientation change.

[Activity(ConfigurationChanges=Orientation)]

This will then call Activity.OnConfigurationChanged when the orientation
changes. All other configuration changes will go through the standard
activity re-creation. It may also help to add Keyboard and KeyboardHidden
to prevent the activity being recreated when a keyboard is slid open or
shut. See the "Configuration Changes" section on this page
http://api.xamarin.com/index.aspx?link=T%3aAndroid.App.Activity

Sly

On 15 December 2011 05:32, Dean Ellis <
reply@reply.github.com

wrote:

There seems to be a big problem with the Orientation change stuff on
Android. After reading the documentation the Activity is re-created each
time the Orientation/Configuration changes. The means the Game object is
being re-created each time, so all the assets are loaded again and again
and again each time the orientation changes.

We need to figure out a way to detect this and keep the same game object/
content manager around and just swap out the Activity/ AndroidGameView.

This will not effect people who just use a fixed screen orientation for
games as the orientation will not change. however this might be the cause
of the Resume issue we have been seeing as well.


Reply to this email directly or view it on GitHub:
#170

@dellis1972
Copy link
Contributor Author

Good find, ill give that a go today
On Dec 15, 2011 10:44 AM, "Steve 'Sly' Williams" <
reply@reply.github.com>
wrote:

Use the following attribute to prevent the activity being recreated on an
orientation change.

[Activity(ConfigurationChanges=Orientation)]

This will then call Activity.OnConfigurationChanged when the orientation
changes. All other configuration changes will go through the standard
activity re-creation. It may also help to add Keyboard and KeyboardHidden
to prevent the activity being recreated when a keyboard is slid open or
shut. See the "Configuration Changes" section on this page
http://api.xamarin.com/index.aspx?link=T%3aAndroid.App.Activity

Sly

On 15 December 2011 05:32, Dean Ellis <
reply@reply.github.com

wrote:

There seems to be a big problem with the Orientation change stuff on
Android. After reading the documentation the Activity is re-created each
time the Orientation/Configuration changes. The means the Game object is
being re-created each time, so all the assets are loaded again and again
and again each time the orientation changes.

We need to figure out a way to detect this and keep the same game object/
content manager around and just swap out the Activity/ AndroidGameView.

This will not effect people who just use a fixed screen orientation for
games as the orientation will not change. however this might be the cause
of the Resume issue we have been seeing as well.


Reply to this email directly or view it on GitHub:
#170


Reply to this email directly or view it on GitHub:
#170 (comment)

@dellis1972
Copy link
Contributor Author

that seems to work, but we now have to update the Viewport manually with the new width and height because the game is not being re-created each time. Looking at sorting that out now.

alxwest pushed a commit to alxwest/MonoGame that referenced this issue May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants