When you say you need a UIView, why is that? UIImageView extends UIView; is that not enough for what you're doing?
I haven't used UIColor.FromPatternImage, but looking more closely at your code: I'm suspicious of disposing the colors and UIViews as you go. Presumably, at some point you are going to need to display the parent view that you're adding them all to, and when you do that, the parent view is going to need those subviews to paint itself, and the subviews are going to need the colors. What exactly is this code meant to do? Maybe there's a better way. On Mon, Jul 4, 2011 at 1:39 AM, Jon Hopkins <[email protected]>wrote: > Hi,**** > > ** ** > > Good news, bad news. If I use a UIImageView, then it works fine, running up > to 500+ iterations without a problem.**** > > My change is simple**** > > ** ** > > private void myTimer2 ()**** > > {**** > > InvokeOnMainThread > (delegate {**** > > **** > > if > (this.Subviews != null) {**** > > > for (int x=0; x<this.Subviews.Length; x++) {**** > > > var sv = this.Subviews[x];**** > > > sv.RemoveFromSuperview ();**** > > > sv.Dispose ();**** > > > sv = null;**** > > > }**** > > > } **** > > > GC.Collect();**** > > **** > > var idx = > (globalcounter % 4) + 1;**** > > > globalcounter++;**** > > > **** > > using > (UIImageView view = new UIImageView (new RectangleF (0, 0, Frame.Width, > Frame.Height))) {**** > > > using (UIImage image = UIImage.FromFile("assets/i" + idx + ".jpg")) {**** > > > view.Image = image;**** > > > AddSubview (view);**** > > > }**** > > }**** > > });**** > > **** > > trace ("added " + > globalcounter);**** > > }**** > > ** ** > > L . Unfortunately, I need a UIView. Did I find a monotouch bug?**** > > ** ** > > Jon**** > > ** ** > > *Von:* [email protected] [mailto: > [email protected]] *Im Auftrag von *Jon Hopkins > *Gesendet:* 04 July 2011 09:36 > *An:* David Moles > *Cc:* [email protected] > *Betreff:* Re: [MonoTouch] 100 times Adding / removing a View > +backgroundImage will always crash !**** > > ** ** > > 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);**** > > }**** > > ** ** > -- David Moles [email protected]
_______________________________________________ MonoTouch mailing list [email protected] http://lists.ximian.com/mailman/listinfo/monotouch
