My favorites | Sign in
Project Logo
                
Search
for
Updated Oct 10, 2008 by parmanoir
QuickStart  

JSCocoaConsole is an interactive console executing Javascript commands. You can call anything here, provided it fits on one line.

Click the help button to execute sample commands.

(If you want to quickstart-understand JSCocoa itself, check HowJSCocoaWorks, JSCocoaInternals, SampleBridgeEvaluation)

Using JSCocoa in your project

As JSCocoa is not a framework (yet?),

How to init JSCocoa depends on the lifetime you want for your JS objects.

  • program lifetime : start JSCocoa in main.c
  • 	[[NSAutoreleasePool alloc] init];
    	id JSCocoa = [JSCocoaController sharedController];
    	[JSCocoa evalJSFile:@"myFile.js"];
    	// Standard ObjC alloc
    	return NSApplicationMain(argc,  (const char **) argv);
  • use and discard lifetime, eg while reacting to button click
same as above, without the need for the autorelease pool.

Garbage Collection

JSCocoa retains objects it uses.

var object = MyObject.instance()

creates an object with a retain count of 1. It will alive until you discard the last reference to it and JavascriptCore's GC kicks in :

	// Remove last reference to object
	object = null
	// Manually collect - object will be destroyed
	JSCocoaController.garbageCollect

Forgetting to set object = null will cause the object to live forever.

Call JSCocoaController.logInstanceStats to check on your objects' lifetime.



Sign in to add a comment
Hosted by Google Code