How to unload all objects when a form is closed?
CapableObjects Forums
Home       Members    Calendar    Who's On
Welcome Guest ( Login | Register )
        



How to unload all objects when a form is... Expand / Collapse
Author
Message
Posted 2008-12-11 17:31:44
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 2012-01-26 14:59:09
Posts: 242, Visits: 828
Hi,

why there is difference in the following behaviours:?

1.

a. Open a form that loads 1000 Eco objects

b. Close the form

c. EcoSpace.Active = false; EcoSpace.Active = true;

Result: 1000 objects loaded

2.

a.  Loading the same 1000 objects with IObjectList iol = EcoServiceHelper.GetExtentService(rhRoot.EcoSpace).AllInstances(typeof(DatenpunktDef));    iol.EnsureObjects();

b. EcoSpace.Active = false; EcoSpace.Active = true;

Result: 0 objects loaded

The only difference I see is that iol is a local variable in a method of the test form, whereas the form in scenario 1. is a private member of the test form. But If I use .Close() on the form containig 1000 objects it doesn't chenge the behaviour.

What's the matter?

/Efim

Post #1414
Posted 2008-12-12 11:58:03
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 2012-01-26 14:59:09
Posts: 242, Visits: 828
The positive result can be achieved if the local reference on the form in question is set to null and GC.collect() is called.

The only thing I don't like is that it should be done in the calling form:

private MyCalledForm myCalledForm = null; 

..................................

if (myCalledForm == null)

   myCalledForm = new MyCalledForm(EcoSpace);

myCalledForm.Show();

........................

if (myCalledForm != null)

{

    myCalledForm = null;

    GC.Collect();

    EcoSpace.Active = false;

    EcoSpace.Active = true;

}

Can I achieve the same without holding the local form reference (myCalledForm in this case) in the calling form?

I tried already to do the same in FromClosed event of the MyCalledForm, but it didn't work.



/Efim
Post #1418
Posted 2008-12-14 13:16:38
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 2011-07-14 17:05:00
Posts: 290, Visits: 2 617
All you need to do is to create an instance of the 2nd form, have the 2nd form own its own EcoSpace instance.  When the form is collected the memory will be collected, which may not be immediately but rather when the .NET GC decides it is needed.

====
Pete
Post #1422
Posted 2008-12-15 09:36:26
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 2012-01-26 14:59:09
Posts: 242, Visits: 828
Hi Pete,

Yes, I had in mind this solution, but I'm not sure so far what other problems can appear when working with multiple EcoSpaces. For ex. when 2 forms have common data or when synchronizing with EcoSpaces of other clients using Remote Persistence.

/Efim

Post #1424
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: HansKarlsen, Jonas Hogstrom, PeterMorris

Permissions Expand / Collapse

All times are GMT +1:00, Time now is 12:08

Powered By InstantForum.NET v4.1.4 © 2012
Execution: 0,250. 8 queries. Compression Disabled.