Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C5 using Assign(oReference as object) Bug
Message
De
13/02/2004 00:55:08
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Problèmes
Titre:
C5 using Assign(oReference as object) Bug
Divers
Thread ID:
00876978
Message ID:
00876978
Vues:
37
For years at my work we've had problem with C5 ocassionally with development environment in VFP 7. When VFP 8.0 came out the problem with the same code happened 10 times more frequently. After spending days narrowing the problem down from a mountain of Code, it boiled down to a reference argument being passed to an assign method. Well while in the assing method the argument passed in was never assigned to the property that the assign method was bound to.

After a few iteration of running this code I'd get a C5 Error. This Error would hardly ever be on the same line of code which made it extremely dificult to fix. But what it boiled down to was the assignment not being made to the property the assign method was bound to. I was told memory was being corrupted and it was a VFP Bug

Anyway if frequent c5 are causing problems, an area to possible look at is if a property assignment isn't being made when an object is being passed as a parameter to an assign method. Here is some sample code that will cause the c5 and the fixes are commented out. Please let me know any thoughts.
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 causes extremly bad 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 
Répondre
Fil
Voir

Click here to load this message in the networking platform