Hi,

 

Unfortunately, it still crashes at the same point around 102 iterations with 

 

jetsam: kernel memory event (90), free: 604, active: 3645, inactive: 2080, 
purgeable: 139, wired: 12350

Mon Jul  4 09:44:34 unknown SpringBoard[801] <Warning>: Received memory 
warning. Level=2

 

This is the timer code.... I'm beginning to think that this is a monotouch 
problem!

 

???

Jon

 

                                private void myTimer ()

                                {

                                                InvokeOnMainThread (delegate {

                                                                

                                                                if 
(this.Subviews != null) {

                                                                                
for (int x=0; x<this.Subviews.Length; x++) {

                                                                                
                var sv = this.Subviews[x];

                                                                                
                sv.RemoveFromSuperview ();

                                                                                
                sv.BackgroundColor.Dispose ();

                                                                                
                sv.Dispose ();

                                                                                
                trace("disposed");

                                                                                
                sv = null;

                                                                                
}

                                                                }

                                                                

                                                                GC.Collect();

                                                                

                                                                trace ("svc=" + 
Subviews.Length);                                            // always 0

                                                                var idx = 
(globalcounter % 4) + 1;

                                                                globalcounter++;

 

                                                                                

                                                                using (UIView 
view = new UIView (new RectangleF (0, 0, Frame.Width, Frame.Height))) {

                                                                                
using (UIImage image = UIImage.FromFile("assets/i" + idx + ".jpg")) {

                                                                                
                using (UIColor color = UIColor.FromPatternImage(image)) {

                                                                                
                                view.BackgroundColor = color;

                                                                                
                                AddSubview (view);

                                                                                
                }

                                                                                
}

                                                                }

                                                });

                                                

                                                trace ("added " + 
globalcounter);

                                }

 

 

Von: [email protected] [mailto:[email protected]] Im Auftrag von David 
Moles
Gesendet: 01 July 2011 18:12
An: Jon Hopkins
Cc: Robert Jordan; [email protected]
Betreff: Re: [MonoTouch] 100 times Adding / removing a View + backgroundImage 
will always crash !

 

(That goes for the add code as well -- anything that involves manipulating 
UIViews. I don't know for sure that this is your problem but it's a good rule 
of thumb in GUI systems regardless.)

On Fri, Jul 1, 2011 at 9:11 AM, David Moles <[email protected]> wrote:

Try invoking the actual removal code on the main thread (with 
NSObject.InvokeOnMainThread or NSObject.BeginInvokeOnMainThread) and see if 
that helps.

 

On Fri, Jul 1, 2011 at 7:10 AM, Jon Hopkins <[email protected]> wrote:

Sorry, still crashes.

using (UIView view = new UIView (new RectangleF (0, 0, Frame.Width, 
Frame.Height))) {

       using (var image = UIImage.FromFile("assets/gallery/pic_" + idx + 
".jpg")) {
               using (var color = UIColor.FromPatternImage(image)) {
                       view.BackgroundColor = color;

                       AddSubview (view);
               }
       }
}

-----Ursprüngliche Nachricht-----
Von: Robert Jordan [mailto:[email protected]]
Gesendet: 01 July 2011 15:59

An: Jon Hopkins
Cc: [email protected]

Betreff: Re: [MonoTouch] 100 times Adding / removing a View + backgroundImage 
will always crash !


On 01.07.2011 15:03, Jon Hopkins wrote:
> Hi,
>
>
>
> Calling this method on a timer will always eventually crash. GC is not
> working here, and I am
>
> Completely out of ideas.....
>
...
>
> view.BackgroundColor =
> UIColor.FromPatternImage(UIImage.FromFile("assets/gallery/pic_" + idx +
> ".jpg"));
>

Try this:

using (var image = UIImage.FromFile(
       "assets/gallery/pic_" + idx + ".jpg"))
using (var color = UIColor.FromPatternImage(image) {
       view.BackgroundColor = color;
}


Robert

_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch





-- 
David Moles

[email protected]

 




-- 
David Moles

[email protected]

 

_______________________________________________
MonoTouch mailing list
[email protected]
http://lists.ximian.com/mailman/listinfo/monotouch

Reply via email to