Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/rtScriptV8/rtScriptNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ using namespace rtScriptV8NodeUtils;
#ifdef RUNINMAIN
bool gIsPumpingJavaScript = false;
#endif
bool gIsDisposingGCObjs = false;

#if NODE_VERSION_AT_LEAST(8,12,0)
#define USE_NODE_PLATFORM
Expand All @@ -119,6 +120,8 @@ class rtNodeContext;

typedef rtRef<rtNodeContext> rtNodeContextRef;

std::vector<rtObjectRef> gcdObjs;
void disposeGarbageCollectedObjs();
class rtNodeContext: rtIScriptContext // V8
{
public:
Expand Down Expand Up @@ -1178,6 +1181,7 @@ rtError rtScriptNode::pump()
}
}
#ifdef RUNINMAIN
disposeGarbageCollectedObjs();
gIsPumpingJavaScript = false;
}
#endif
Expand All @@ -1197,6 +1201,7 @@ rtError rtScriptNode::collectGarbage()
Local<Context> local_context = Context::New(mIsolate);
Context::Scope contextScope(local_context);
mIsolate->LowMemoryNotification();
disposeGarbageCollectedObjs();
//#endif // RUNINMAIN
return RT_OK;
}
Expand Down Expand Up @@ -1452,4 +1457,18 @@ rtError createScriptNode(rtScriptRef& script)
return RT_OK;
}

void disposeGarbageCollectedObjs()
{
if (gIsDisposingGCObjs == false)
{
gIsDisposingGCObjs = true;
size_t noelems = gcdObjs.size();
for (size_t i=0; i<noelems; i++)
{
gcdObjs[i].send("dispose");
}
gcdObjs.erase(gcdObjs.begin(), gcdObjs.begin()+noelems);
gIsDisposingGCObjs = false;
}
}
#endif // RTSCRIPT_SUPPORT_NODE
5 changes: 3 additions & 2 deletions src/rtScriptV8/rtWrapperUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static pthread_mutex_t sObjectMapMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
#endif

using namespace std;
extern vector<rtObjectRef> gcdObjs;

//-----------------------------------

Expand Down Expand Up @@ -106,7 +107,7 @@ rtWrapperSceneUpdateExit();
{
if (NULL == parentRef)
{
temp.send("dispose");
gcdObjs.push_back(temp);
}
}
}
Expand Down Expand Up @@ -188,7 +189,7 @@ rtWrapperSceneUpdateExit();
{
if (NULL == parentRef)
{
temp.send("dispose");
gcdObjs.push_back(temp);
}
}
}
Expand Down