How to handle 5.2 Performance and Resource Management issue?

Recently, I came across 5.2 Performance and Resource Management issue. This is problem because you do not really get whole lots of direction as to what is wrong with your application. So here is basic tips to troubleshoot this issue very quickly.

1) Check your tombstoning and make sure it is quick and you are not saving large data back and forth into the isolated storage

2) MAKE SURE you dispose everything specially any type of streams. This was in fact one of my issue with one of the my app. Below is the sample code that fixed my app issue.

Problem Code:

public void PlaySound(string sound)

{

  using (Stream stream = TitleContainer.OpenStream(sound))

  {

    AnimalSoundEffect = SoundEffect.FromStream(stream);

    FrameworkDispatcher.Update();

    AnimalSoundEffect.Play();

  }

}

 

Fix Code:

public void PlaySound(string sound)

{

    Stream stream = null;

    try

    {

        stream = TitleContainer.OpenStream(sound);

        AnimalSoundEffect = SoundEffect.FromStream(stream);

        FrameworkDispatcher.Update();

        AnimalSoundEffect.Play();

    }

    catch (Exception ex)

    {

        LogDto logDto = new LogDto();

        logDto.Message = ex.Message;

        logDto.Title = “Sound Failure”;

        ToeTapzServiceViewModel.Instance.LogException

        (Settings.Instance.CurrentTrackingAppId, “Pull And Speak” , logDto);

    }

    finally

    {

        // Make sure to Dispose this stream or the garbage collector

        // takes FOREVER to kill it and the app loads REALLY slow on the next launch

        if (stream != null)

        {

            stream.Dispose();

        }

    }

}

 

Notice the problem code above. I do infact disposes my stream using “Using” but that in fact did not work for me so I had to result to good old fasion style using finally to dispose. There must be delay how “Using” disposes resources vs. actually calling Dispose method directly.

About toetapz

Henry Lee is founder of various start-ups and is passionate about the technology. He is also the author of the book Beginning Windows Phone Development 3nd edition from Apress (http://bit.ly/wp_apress_3rd). He works with various Fortune 500 companies delivering large multi-million dollar projects. He recently formed start-up company called ToeTapz.com focusing his energy on delivering mobile applications to the consumers. In his spare time, he dedicates his effort to help his .NET community by delivering sessions at the technology events. He enjoys talking with other technologist about current trends in the technology and sharing business insights with fellow colleagues. Often you will find Henry at local cigar bar enjoying a cigar and a drink trying to come up with next big mobile application.
This entry was posted in Marketplace Certification, Windows Phone 7 and tagged , . Bookmark the permalink.

One Response to How to handle 5.2 Performance and Resource Management issue?

  1. Pingback: How to handle Application test failed – Error: 6.5 Applications that Play Music? | Toetapz's Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s