09-23-2010 07:40 PM
While Peter's approach is the surest cure to your problems, even if you employ that, add some debug prints (such as printing m.getClass().toString() at least) to find out the actual reason. His code is treating the symptoms, but eventually you'll have to find the root of the problem and fix that once and for all.
09-23-2010 08:24 PM
Nothing's too hokey Peter. But what does 'previous instance still active' mean when I exit?
Justin
09-24-2010 04:14 AM
That is one of those things that at one point I think I understood, but I don't now....
Worthy of a new Thread?
09-24-2010 04:40 AM
Hey. The class is a VerticalFieldManager. It seems that when you add an ObjectListField to a MainScreen, you actually add a VFM with an OLF...
The VFM has a manager which is a TitleStatusManager. That has a manager which is the MainScreen.
I really don't know where to look to understand it. My code below is as much as I understand now. It gets an IllegalArgumentException deleting the VFM from the TitleStatusManager.
SRSS_OLF myOLF = (SRSS_OLF)m_everyOLF.elementAt(i);
Manager m = myOLF.getManager();
if (m != null) {
m.delete(myOLF); /// m is a VFM
Manager mm = m.getManager();
if (mm != null)
mm.delete(m); /// mm is a TitleStatusManager (exception on this line). The next level above mm is the MainScreen (RepMS)
}
m_sharpRSSMainScreen.add(myOLF);
09-24-2010 05:05 AM
From memory, a MainScreen actually has 3 managers under the covers, that you normally don't see. There is the status area Manager, the actual screen (the delegate Manager) and the Title area Manager. I think these are all VFMs or extensions there-of.
However if you use a MainScreen normally, you don't need to see this and you shouldn't have too. I suspect arkadzy is right suggesting you should look at the code that is supposed to remove these Fields, rather than band-aid fixing the problem.
OK, here is another suggestion. Instead of worrying about all the Fields, why not add them all to a VFM, then just move the VFM from one screen to the next?
09-24-2010 07:16 AM
09-24-2010 07:24 AM
09-24-2010 03:34 PM
Hi Justin. I don't understand your comment about the VFM. You said, "when you add an ObjectListField to a MainScreen, you actually add a VFM with an OLF". I don't think that's it. When you invoke MainScreen's add method to add the OLF, you are actually adding the OLF to a VFM the MainScreen already owns. I would guess a MainScreen or any Screen would get a mite peeved if you try to delete one of its Managers. So your comment "an IllegalArgumentException deleting the VFM" is not surprising.
But that's different from the IllegalState exception you originally asked about. That comes from an OLF when you try to add it to a Manager when it thinks it already has one. I originally thought that happened because add() adds to the MainScreen's delegate Manager but deleteAll() deletes from the MainScreen itself, so the OLF never got deleted. But now you've made it clear that it's not even the same MainScreen!
So here's another try: You added the OLFs to a VFM owned by a MainScreen, then closed the MainScreen. The VFM can't get garbage-collected because the OLFs still have a reference to it -- that's what getManager() returned. So when you try to add the OLF to a new MainScreen, the OLF thinks it is still managed.
The flaw in that reasoning is that it assumes you have the same OLF. I thought you were creating a new one from persistent store. Can you clarify that? I don't know what you meant by "previous instance still active", either, but it's clear that something is hanging around when you don't expect it to.
If you do have the same OLFs, Peter's defensive programming should take care of the problem. (And arkadyz is right -- defensive programming often masks the root cause of the problem it defends against. But it sounds nicer than "hokey".) It asks each OLF if it is already managed, and if so, tells the Manager to release the OLF. Then you can add the OLF to a new Manager (the new MainScreen's delegate VFM). In your version, you then go on to delete the Manager's Manager, which is not needed and does not work.
If this chain of reasoning is somewhere close to right, another way is to delete the OLFs when you close the old MainScreen -- maybe put a loop in its onClose() method. Come to think of it, that might be a good thing to do anyway, whether I have it right or not. Somehow we seem to have fallen into C++ do-it-yourself memory management.
09-24-2010 04:09 PM
09-24-2010 04:39 PM