diff --git a/ReactCommon/yoga/yoga/Yoga.c b/ReactCommon/yoga/yoga/Yoga.c index 4222c230c..6a550206a 100644 --- a/ReactCommon/yoga/yoga/Yoga.c +++ b/ReactCommon/yoga/yoga/Yoga.c @@ -308,6 +308,7 @@ static inline float YGResolveValueMargin(const YGValue *const value, const float } int32_t gNodeInstanceCount = 0; +int32_t gConfigInstanceCount = 0; WIN_EXPORT YGNodeRef YGNodeNewWithConfig(const YGConfigRef config) { const YGNodeRef node = gYGMalloc(sizeof(YGNode)); @@ -373,15 +374,21 @@ int32_t YGNodeGetInstanceCount(void) { return gNodeInstanceCount; } +int32_t YGConfigGetInstanceCount(void) { + return gConfigInstanceCount; +} + YGConfigRef YGConfigNew(void) { const YGConfigRef config = gYGMalloc(sizeof(YGConfig)); YG_ASSERT(config, "Could not allocate memory for config"); + gConfigInstanceCount++; memcpy(config, &gYGConfigDefaults, sizeof(YGConfig)); return config; } void YGConfigFree(const YGConfigRef config) { gYGFree(config); + gConfigInstanceCount--; } static void YGNodeMarkDirtyInternal(const YGNodeRef node) { @@ -3426,7 +3433,8 @@ bool YGConfigGetUseWebDefaults(const YGConfigRef config) { } void YGSetMemoryFuncs(YGMalloc ygmalloc, YGCalloc yccalloc, YGRealloc ygrealloc, YGFree ygfree) { - YG_ASSERT(gNodeInstanceCount == 0, "Cannot set memory functions: all node must be freed first"); + YG_ASSERT(gNodeInstanceCount == 0 && gConfigInstanceCount == 0, + "Cannot set memory functions: all node must be freed first"); YG_ASSERT((ygmalloc == NULL && yccalloc == NULL && ygrealloc == NULL && ygfree == NULL) || (ygmalloc != NULL && yccalloc != NULL && ygrealloc != NULL && ygfree != NULL), "Cannot set memory functions: functions must be all NULL or Non-NULL"); diff --git a/ReactCommon/yoga/yoga/Yoga.h b/ReactCommon/yoga/yoga/Yoga.h index d5c5258a7..86b63dedb 100644 --- a/ReactCommon/yoga/yoga/Yoga.h +++ b/ReactCommon/yoga/yoga/Yoga.h @@ -228,6 +228,7 @@ WIN_EXPORT void YGConfigSetPointScaleFactor(const YGConfigRef config, const floa // YGConfig WIN_EXPORT YGConfigRef YGConfigNew(void); WIN_EXPORT void YGConfigFree(const YGConfigRef config); +WIN_EXPORT int32_t YGConfigGetInstanceCount(void); WIN_EXPORT void YGConfigSetExperimentalFeatureEnabled(const YGConfigRef config, const YGExperimentalFeature feature,