FoxPro Programming
Re: Collection object releasing problem
08/11/2006
08:26:00 PM
1VD17SND6 Show this entire thread in new window
Gratar Image based on email address
From:
Steven Black
To:
Myron Kirby 
Attachments:
None
Hi Myron,

Try CLEAR CLASS ClassName

From help: Clears a class definition from memory. When an instance of a class is created, Visual FoxPro keeps the class definition in memory after the instance is released. Use CLEAR CLASS to clear a class definition from memory after its instance is released.

It makes some intuitive sense that VFP would cache class definitions for performance reasons. So it's not just a matter of creating and releasing objects. The artefact in memory, the class definition, is what VFP is asking you about...

**--** Steve


I have spent many hours trying to determine why after running some code and then trying to edit the code I get the message "Remove classes from memory?". I finally identified the source of the problem and a work-around but still don't understand the why.

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

* -> Problem:
* After the code runs it appears that an object/class is not releasing.
* After running the code when you attempt to modify the "prg" you get the message
* "Remove classes from memory?".
* It appears that this only occurs when the objects being added are based on
* different classes defined in the same Prg that are sub classed
* from the same parent class (or direct relative) defined in the same "prg".
*
* -> Work-around:
* Move class def's to separate "prg".
*
* -> Ref:
* Vfp9, Sp1
*
* -> Notes:
* Tried manually removing all the objects from the collection in a clean-up and
* still didn't help.
*
* -> Problem does not occur in the following scenarios:
* > The added objects are based on base classes
* > The added objects are based both based on "clsRef1a"
* > The added objects are from the same class def.
* For example if both are based on "clsRef2a".
* > The added objects are from the diff classes with diff parent classes.
* For example:
* Obj 1 = class clsRef2a, parent clsRef1a
* Obj 2 = class clsRef2b, parent clsRef1b
* > If the parent class def's are defined in another prg.
* For example:
* Take all the DEFINEs and move them to
* "TestCollectionProbClassLib"
* Then add:
* "SET PROCEDURE TO DEV\TestCollectionProbClassLib"

* -> Code to re-create problem. Run the code and then
* try to modify the "prg"

loJobs = NEWOBJECT ("Collection")
loJobs.ADD(NEWOBJECT ("clsRef2a"), "Test1")
loJobs.ADD(NEWOBJECT ("clsRef2b"), "Test2")

loJobs.Remove(-1)
loJobs = .null.

RETURN .T.
*!* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


DEFINE CLASS clsRef2a AS clsRef1a
ENDDEFINE

DEFINE CLASS clsRef2b AS clsRef1b
ENDDEFINE

DEFINE CLASS clsRef1a AS clsRef0
ENDDEFINE

DEFINE CLASS clsRef1b AS clsRef0
ENDDEFINE

DEFINE CLASS clsRef0 AS CUSTOM
ENDDEFINE