Subj : Help with embedding spidermonkey please!!! To : netscape.public.mozilla.jseng From : "Blacksage" Date : Sat Nov 08 2003 10:47 pm Hey, We have been attempting to embed Spidermonkey into an application for some time now, and are failing miserably. We have inserted the engine into the app with little difficulty, it initialises and runs scripts fine, however it doesn't cleanup properly and results in dumping of a heap of memory (which we believe is likely the remnants of the java standard classes). The application is being developed in wxWindows, however for simplicity sake we have the code in a small .cpp below for you to see: #ifndef LEAKDETECT_H_ #define LEAKDETECT_H_ #if defined(_DEBUG) && defined(_MSC_VER) && (_MSC_VER >= 1000) #include #pragma warning(disable:4514) static int enable_crt_debug() { return _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); } int crt_debug_result = enable_crt_debug(); #endif #endif #define XP_WIN #include using namespace std; #include "js/jsapi.h" class ScriptEngine { public: ScriptEngine(); ~ScriptEngine(); JSRuntime *m_JSRunTime; JSContext *m_JSContext; JSObject *m_GlobalObject; }; ScriptEngine::ScriptEngine() { cout << "Contstructor Start" << endl; m_JSRunTime = NULL; m_JSContext = NULL; m_GlobalObject = NULL; m_JSRunTime = JS_NewRuntime(4 * 1024 * 1024); m_JSContext = JS_NewContext(m_JSRunTime, 8 * 1024); JSClass globalClass = { "Global", 0, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub }; m_GlobalObject = JS_NewObject(m_JSContext, &globalClass, NULL, NULL); JS_InitStandardClasses(m_JSContext, m_GlobalObject); cout << "Contstructor End" << endl; } ScriptEngine::~ScriptEngine() { cout << "Destructor Start" << endl; if (m_JSContext) { JS_DestroyContext(m_JSContext); m_JSContext = NULL; } JS_DestroyRuntime(m_JSRunTime); m_JSRunTime = NULL; JS_ShutDown(); cout << "Destructor End" << endl; } int main() { ScriptEngine *cScriptEngine; cScriptEngine = new ScriptEngine(); delete cScriptEngine; cScriptEngine = NULL; return 0; } Upon creating this .cpp it doesnt even run to instead breaking during calling JS_DeleteContext. Wehave tried virtually everything we can think of, its almost as if the context is lost or something. For example take the code from the destructor, and place it directly folloing the last line of the constructor, and everything works fine... If you have any ideas whats happening we would be greatly appreciative! Kingsley .