If i understand what you are asking i think what you want to do is use the IDisposable interface which will handle the cleanup of resources for you.
Your usage having used IDisposable would then be
using(var adaptor = new GenericFragmentPagerAdaptor(SupportFragmentManager))
{
adaptor.AddFragmentView((i, v, b) => {
var view = i.Inflate(Resource.Layout.tab, v, false);
textView = new TextView(view.Context);
textView.Text = "Test1";
view.FindViewById<FrameLayout>(Resource.Id.mainFrame).AddView(textView);
return view;
});
}
By doing it this way, anything outside the
using(){} would be automatically cleaned up by the garbage disposal process.
An example of implementing IDisposable would be something like this:
public class MyClass : IDisposable
{
private bool Disposed { get; set; }
public void Dispose()
{
this.Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (!this.Disposed)
{
if (disposing)
{
}
}
this.Disposed = true;
}
}
using(var cl = new MyClass())
{
}