MCPcopy Create free account
hub / github.com/anjo76/angelscript / ~asCScriptObject

Method ~asCScriptObject

sdk/angelscript/source/as_scriptobject.cpp:408–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406}
407
408asCScriptObject::~asCScriptObject()
409{
410 if( extra )
411 {
412 if( extra->weakRefFlag )
413 {
414 extra->weakRefFlag->Release();
415 extra->weakRefFlag = 0;
416 }
417
418 if( objType->engine )
419 {
420 // Clean the user data
421 for( asUINT n = 0; n < extra->userData.GetLength(); n += 2 )
422 {
423 if( extra->userData[n+1] )
424 {
425 for( asUINT c = 0; c < objType->engine->cleanScriptObjectFuncs.GetLength(); c++ )
426 if( objType->engine->cleanScriptObjectFuncs[c].type == extra->userData[n] )
427 objType->engine->cleanScriptObjectFuncs[c].cleanFunc(this);
428 }
429 }
430 }
431
432 asDELETE(extra, SExtra);
433 }
434
435 // The engine pointer should be available from the objectType
436 asCScriptEngine *engine = objType->engine;
437
438 // Destroy all properties
439 // In most cases the members are initialized in the order they have been declared,
440 // so it's safer to uninitialize them from last to first. The order may be different
441 // depending on the use of inheritance and or initialization in the declaration.
442 // TODO: Should the order of initialization be stored by the compiler so that the
443 // reverse order can be guaranteed during the destruction?
444 for( int n = (int)objType->properties.GetLength()-1; n >= 0; n-- )
445 {
446 asCObjectProperty *prop = objType->properties[n];
447 if( prop->type.IsObject() )
448 {
449 // Destroy the object
450 asCObjectType *propType = CastToObjectType(prop->type.GetTypeInfo());
451 if( prop->type.IsReference() || propType->flags & asOBJ_REF )
452 {
453 void **ptr = (void**)(((char*)this) + prop->byteOffset);
454 if( *ptr )
455 {
456 FreeObject(*ptr, propType, engine);
457 *(asDWORD*)ptr = 0;
458 }
459 }
460 else
461 {
462 // The object is allocated inline. As only POD objects may be allocated inline
463 // it is not a problem to call the destructor even if the object may never have
464 // been initialized, e.g. if an exception interrupted the constructor.
465 asASSERT( propType->flags & asOBJ_POD );

Callers 1

DestructMethod · 0.95

Calls 9

CastToObjectTypeFunction · 0.85
IsObjectMethod · 0.80
GetTypeInfoMethod · 0.80
CallObjectMethodMethod · 0.80
IsFuncdefMethod · 0.80
ReleaseMethod · 0.45
GetLengthMethod · 0.45
IsReferenceMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected