Bug 1056 - Servercell.cs bug, when pressing button
Summary: Servercell.cs bug, when pressing button
Alias: None
Product: iOS
Classification: Xamarin
Component: Debugger ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2011-09-26 11:51 UTC by Ploetzeneder Andreas
Modified: 2011-10-05 17:34 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

file with the problem (786.40 KB, application/zip)
2011-09-26 11:51 UTC, Ploetzeneder Andreas

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Ploetzeneder Andreas 2011-09-26 11:51:58 UTC
Created attachment 495 [details]
file with the problem

ihave a strange issue, when i press on the touchdown,...of the buttonrund in Servercell.cs the app crashes....and i have simpyl no idea why?

Maybe i have not understood something, maybe it is a bug,...

maybe u can additionally show me how to rise an UIactionsheet from there
Comment 1 Sebastien Pouliot 2011-09-26 16:11:29 UTC
It's a known issue (see bug #134) where MonoTouch is not (yet) able to hide the GC actions from developers. 

When you override GetCell, i.e. "public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)", like you're doing in both:
* Siemens3G/DetailtabelleDataSource.cs (86, 37)
* Siemens3G/HaupttabelleDataSource.cs (62, 37)

what happens is that you're overriding a native (ObjectiveC) object, i.e. the caller is native. So if you create a managed instance (the cell) and return it then that *managed* instance won't exists anymore (only the native part will). That makes the object without any reference and the GC can (and does) collect it. When your application goes back into managed code to access the cell, it's not there and the crash occurs.

The workaround (for current releases of MonoTouch) is to keep manual reference to the cells you are creating. E.g.

private List<UITableViewCell> cells = new List<UITableViewCell> ();
cells.Add (cell);

Since a managed reference will exists to your cells, they won't be collected and no crash will occur. I tried it on your attachment and, with the workaround in place, cannot get it to crash.

We'll likely have a better, less intrusive fix, in the future but until then let us know if this solve your issue (and I'll mark it as a duplicate of #134 so you'll get an email when that better fix becomes available).

note: for UIactionsheet you better ask on stackoverflow.com or on the mailing-list
Comment 2 Jeffrey Stedfast 2011-09-26 17:25:16 UTC
Andreas: you probably want to use UIAlertView and not UIActionSheet, in which case:

UIAlertView alert = new UIAlertView ("Error!", ex.Message, null, "Dismiss", null);
alert.Show ();
Comment 3 Ploetzeneder Andreas 2011-10-05 07:52:42 UTC
I wanted to use a uiactionsheet,...starting from the bottom,...

the cell problem is not solved yet :/
Comment 4 Sebastien Pouliot 2011-10-05 08:08:14 UTC
> I wanted to use a uiactionsheet,...starting from the bottom,...
>> note: for UIactionsheet you better ask on stackoverflow.com or on the
>> mailing-list

> the cell problem is not solved yet :/

I think we're not understanding each other correctly. Can you show me how you applied the suggestion from comment #6 into your code ?
Comment 5 Ploetzeneder Andreas 2011-10-05 08:14:49 UTC
damned my fault :/ i am sry!
Comment 6 Sebastien Pouliot 2011-10-05 08:21:03 UTC
There's no fault, just unsolved mysteries ;-)

Does it means you got your cell-issue under control ?
Comment 7 Ploetzeneder Andreas 2011-10-05 09:01:28 UTC
yes! thx
Comment 8 Sebastien Pouliot 2011-10-05 17:34:36 UTC
ok, closing bug.

Please bring your UIActionSheet question to the mailing-list where more eyes and brains will be available to provide guidance.