Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
BUG: skip the Assign destroy object or fire a C5 crash
Message
De
11/04/2004 22:26:35
 
 
À
09/04/2004 10:51:18
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00893546
Message ID:
00893948
Vues:
19
Fabio, I posted this bug a few months ago on the UT but I didn't have near the response you did. Anyway I opened a support incident with MS back in Feb (I should say around February) and they confirm with me that this is a bug in VFP. This is a bug that that has been around since _Assign methed has been around but it surfaces more in VFP 8.0 more then prior versions.

I was told that there are a few way to keep the bug from happening, one is to make the assignment in the assign method but there are a few other way to keep the bug from surfacing. However making the assignment is the for sure fix. The only other fix is to disable Access and Assign, which I don't think anybody wants, right?


If you are interested here is the code I submitted to MS at the beginning of the year. In my code if you were to comment out the class definition to have less then 5 assign method the C5 error will not occur but it will cause a memory leak. Anyway this is commented in my code below.
LOCAL i, starttime

FOR i = 1 TO 10000
	WAIT WINDOW "Count Number: " + ALLTRIM(STR(i)) NOWAIT 
	RunCode()
ENDFOR 

FUNCTION RunCode()
LOCAL oObjectFactory as Object, oProducedObject as Object 
	
	oObjectFactory = CREATEOBJECT("ObjectFactory")
	oProducedObject = oObjectFactory.ReturnAnObject()
&& Fix number 1 (Real fix in _assign method below)
&& Uncommenting this assignment will keep C5 from
&& happening
&& oObjectFactory = ""
ENDFUNC 

DEFINE CLASS ObjectFactory as Custom
	oObjectRef = ""

	FUNCTION ReturnAnObject() as Object
	LOCAL oObjectRef as Object 
		oObjectRef = CREATEOBJECT("ProducedObject")
&& This assignment is in a sense the problem
		oObjectRef.Configuration = THIS
		RETURN oObjectRef
	ENDFUNC 
ENDDEFINE 

DEFINE CLASS ProducedObject as Custom
&&If class definition is small 
&&enough a C5 may not occur.
&&5 or less of a combination of  array member
&&or member with assign method will not
&&cause C5 error but will create a memory leak

	Configuration = ""
&&Members with assign methods
	MemberString1 = ""
	MemberString2 = ""
	MemberString3 = ""
	MemberString4 = ""
	MemberString5 = ""
	
	DIMENSION MemberArray1(1)
	DIMENSION MemberArray2(1)
	DIMENSION MemberArray3(1)
	DIMENSION MemberArray4(1)
	DIMENSION MemberArray5(1)
	DIMENSION MemberArray6(1)

	FUNCTION Configuration_Assign(oObjectRef as object)	
		IF TYPE("oObjectRef.Class") = "C"
&& If this next assignment isn't made a C5 may occur
&& if the reference to oOjectRef is explicitly 
&& release somewhere higher in call stack.
*!*				THIS.Configuration = oObjectRef
		ENDIF 
	ENDFUNC 
*********************************************************
	FUNCTION MemberString1_Access()
		RETURN THIS.MemberString1
	ENDFUNC 
	FUNCTION MemberString1_Assign(StringValue as String)
		IF TYPE("StringValue") = "C"
			THIS.MemberString1 = StringValue
		ENDIF 
	ENDFUNC 
*********************************************************

*********************************************************
	FUNCTION MemberString2_Access()
		RETURN THIS.MemberString2
	ENDFUNC 
	FUNCTION MemberString2_Assign(StringValue as String)
		IF TYPE("StringValue") = "C"
			THIS.MemberString2 = StringValue
		ENDIF 
	ENDFUNC 
*********************************************************
*********************************************************
	FUNCTION MemberString3_Access()
		RETURN THIS.MemberString3
	ENDFUNC 
	FUNCTION MemberString3_Assign(StringValue as String)
		IF TYPE("StringValue") = "C"
			THIS.MemberString3 = StringValue
		ENDIF 
	ENDFUNC 
*********************************************************
*********************************************************
	FUNCTION MemberString4_Access()
		RETURN THIS.MemberString4
	ENDFUNC 
	FUNCTION MemberString4_Assign(StringValue as String)
		IF TYPE("StringValue") = "C"
			THIS.MemberString4 = StringValue
		ENDIF 
	ENDFUNC 
*********************************************************
*********************************************************
	FUNCTION MemberString5_Access()
		RETURN THIS.MemberString5
	ENDFUNC 
	FUNCTION MemberString5_Assign(StringValue as String)
		IF TYPE("StringValue") = "C"
			THIS.MemberString5 = StringValue
		ENDIF 
	ENDFUNC 
*********************************************************
ENDDEFINE 
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform