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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:35:54+00:00 2026-06-01T07:35:54+00:00

For convenience, I am using a helper class that allow to display a wait

  • 0

For convenience, I am using a helper class that allow to display a wait indicator without needing a variable / reference into each view. The class implement a static method public

static void ShowActivityIndicator(UIView view, bool animated,  UIActivityIndicatorViewStyle style)

In this method, I am creating a DFActivity indicator and display it on the view given in parameter:

DFActivityIndicator activityIndicator = new DFActivityIndicator(view.Bounds);
view.AddSubview(activityIndicator);
activityIndicator.LabelText = NSBundle.MainBundle.LocalizedString("Loading...", "");
activityIndicator.Indicator.ActivityIndicatorViewStyle = style;
activityIndicator.Show(true);

The constructor of the method is:

public DFActivityIndicator(RectangleF frame) : base(frame)
{      

  Indicator = new UIActivityIndicatorView(UIActivityIndicatorViewStyle.Gray);
  this.AddSubview(Indicator);
  Indicator.StartAnimating();
  Indicator.Frame = new RectangleF(0.0f, 0.0f, 20.0f, 20.0f);
  Indicator.StartAnimating();

  //...

  Label = new UILabel(Bounds);

  RotationTransform = CGAffineTransform.MakeIdentity();
  NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidChangeStatusBarOrientationNotification, DeviceOrientationDidChange, this);

}

The observer is here to be able to rotate the indicator when the interface is rotated. When, the indicator is not anymore needed, I have an other static method:

 public static bool HideActivityIndicator(UIView view, bool animated)
{
  UIView viewToRemove = null;
  foreach(UIView v in view.Subviews)
  {
    if (v is DFActivityIndicator)
    {
      viewToRemove = v;
    }
  }

  if (viewToRemove != null)
  {
    DFActivityIndicator activityIndicator = viewToRemove as DFActivityIndicator;
    NSNotificationCenter.DefaultCenter.RemoveObserver(activityIndicator, UIApplication.DidChangeStatusBarOrientationNotification, null);
    activityIndicator.RemoveFromSuperview();
    activityIndicator.Dispose();
    activityIndicator = null;
    return true;
  }
  else
  {
    return false;
  }
}

This is working fine, expect the Mono profiler indicates that each time I am calling ShowActivityIndicator, each instance is kept into memory even if I call HideActivityIndicator for all instances . The memory of my application is then just increasing until crashing (seems thus be a memory leak). For debugging, I tried to remove the observer on orientation changes:
NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidChangeStatusBarOrientationNotification, DeviceOrientationDidChange, this))
and… the code is not leaking anymore. Is it a MonoTouch bug or I am doing something else wrong?

  • 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-06-01T07:35:55+00:00Added an answer on June 1, 2026 at 7:35 am

    Yes, I think you are not using the AddObsever/RemoveObserver methods correctly.

    Here is what you are doing with the overloads you are using:

    NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidChangeStatusBarOrientationNotification, DeviceOrientationDidChange, this);
    

    You are registering to receive notifications for status bar orientation changes, which will trigger the DeviceOrientationChange callback, if these notifications come from this. So your callback will never be triggered (since your DFActivityIndicator never posts such a notification) but, the default center (or better, the series of objects that you mentioned in the comments) will hold a reference to the view.

    NSNotificationCenter.DefaultCenter.RemoveObserver(activityIndicator, UIApplication.DidChangeStatusBarOrientationNotification, null);
    

    You are trying to remove a view instead of a notification observer. No need to explain the remaining parameters.

    Here is what you should do:

    //To add the observer:
    NSObject observerObject;
    //..
    this.observerObject = NSNotificationCenter.DefaultCenter.AddObserver(UIApplication.DidChangeStatusBarOrientationNotification, DeviceOrientationDidChange)
    //..
    //To remove the observer:
    NSNotificationCenter.DefaultCenter.RemoveObserver(this.observerObject);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a super class with a convenience constructor as follows (using ARC):
What are common and convenient ways for projects that are using jquery or bootstrap
I have a convenience class for encoding URI's. In it I've created three methods
I am developing some convenience wrappers around another software package that defines a bash
I often use convenience functions that return pointers to static buffers like this: char*
I've started using the XmlnsDefinition attribute to tie together some CLR namespaces into a
I'd been using the answer provided in the PyGTK FAQ , but that doesn't
I'm creating a convenience macro. Part of the convenience is that a regular expression
When I'm using jQuery in no conflict mode I still like the convenience of
So I have a helper method that looks something like the following: private D

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.