2009/3/17 MJ <[email protected]>: > > Say you dispose of a context and want V8 to purposefully run a global > GC. Is there a way to make that happen that you know of. And when you
When you create a context then V8 will run a global GC if it hasn't run a global GC since the last time a context was disposed of. This is the current heuristic and it is subject to change. Doing too many global GCs is a good way to slow down your program and happens surprisingly often on platforms that allow the programmer to override the system heurstics. Some Java VMs will ignore the System.gc() method for this reason. > say when V8 thinks its memory is low. Does V8 have a certain block > size of memory that it will allocate in? And if so what if V8 gets to > that limit and you keep trying to create objects? V8 has a bunch of heuristics to determine when to do a global GC. There is an upper limit, but you don't have to hit it to get a global GC. Normally the heuristics are only triggered when the young generation fills up and it is time to determine whether to do a young generation or a global GC. There are some API calls that help indicate to V8 that a global GC is wanted next time the young generation fills up. The V8 GC support is designed primarily to manage V8's memory. As a secondary aim it can be used (with weak handles etc.) to manage memory used in the host application. Since all the heuristics that control the GC are memory based it can't very well be used to control other resources. Examples of other resources that people often want the GCs help to clean up are open file descriptors, database connections, unflushed data. This is unlikely to work in a satisfactory way since your non-memory resources will only be cleaned up if the memory system of V8 is under pressure. > > I also notice there are some flags you can send V8 about its GC. Have > you ever tried any of these flags? > > On Mar 17, 9:15 am, Alex Iskander <[email protected]> wrote: >> v8 will clean the objects up if it/when garbage collects. It garbage >> collects when it thinks it is low on memory. >> >> If programterminatiom happens first, the operating system will, >> naturally, reallocate those resources. >> >> Sent from Alex's iPhone >> >> On Mar 17, 2009, at 8:59 AM, MJ <[email protected]> wrote: >> >> >> >> > Actually I had one small question you guys might be able to answer. If >> > a user writes a JavaScript file, and has some JavaScript classes in >> > there and is creating new class objects in his or her script, is it >> > guaranteed that V8 will manage the memory for those objects and clean >> > it up. These classes are not bound to any C++ classes they are classes >> > defined in JavaScript. >> >> > On Mar 17, 8:27 am, [email protected] wrote: >> >> Ok, thanks you guys you have been a great help. I think I have >> >> narrowed down the issue and so far my tests have been successful and >> >> have not seen the crash (crossing fingers). Its great to know there >> >> is >> >> a place to go to discuss issues on something that is not greatly >> >> documented. Thanks again. >> >> >> On Mar 17, 2:40 am, Søren Gjesse <[email protected]> wrote: >> >> >>> The creation and handling of the objects for the function call >> >>> looks OK. >> >>> Just make sure that the local handles are not used in C++ anywhere >> >>> outside >> >>> the handle scope they where created in. Also make sure that the >> >>> boundFunc is >> >>> valid that is stored in a handle in an outer handle scope or in a >> >>> persistent >> >>> handle. >> >>> Regards, >> >>> Søren >> >> >>> On Tue, Mar 17, 2009 at 12:50 AM, <[email protected]> wrote: >> >> >>>> No I have not tried Debug mode yet, I will have to give that a try. >> >>>> But while looking through my code, I was wondering about >> >>>> dynamically >> >>>> creating V8 objects. There are many times I handle events and >> >>>> need to >> >>>> dynamically create an object and call a bound method from the >> >>>> script. >> >>>> As of right now I create a member in my class that is a v8::Handle< >> >>>> v8::Object > and then when i need to I create a new object and then >> >>>> setup the object to be called into script. >> >> >>>> All are being created under a new handle and context scope: >> >> >>>> v8::Local< v8::Object > obj = v8::Object::New(); >> >> >>>> obj->Set( v8::String::New( "FieldName" ), v8::Object::New() ); >> >> >>>> v8::Local< v8::Object > objField = obj->Get( v8::String::New >> >>>> ( "FieldName" ) )->ToObject(); >> >> >>>> v8::Handle< v8::Array > arr = v8::Array::New( cnt ); >> >> >>>> for ( unsigned int i = 0; i < cnt; i++ ) >> >>>> { >> >>>> arr->Set( v8::Integer::New( i ), >> >>>> v8::String::New( tagData[ i ].c_str() ), >> >>>> v8::ReadOnly ); >> >>>> } >> >> >>>> objField ->Set( v8::String::New( field.c_str() ), arr, >> >>>> v8::ReadOnly ); >> >> >>>> v8::Handle< v8::Value > argv[ 1 ] = { obj }; >> >> >>>> v8::TryCatch tryCatch; >> >>>> { >> >>>> boundFunc->Call( owner, 1, argv ); >> >>>> } >> >>>> Would you say this is the correct way to handle dynamically >> >>>> creating >> >>>> objects to call into the script? >> >> >>>> On Mar 16, 1:06 pm, Søren Gjesse <[email protected]> wrote: >> >>>>> Have you tried running the code in debug mode? V8 has a lot of >> >>>>> assertions >> >>>>> which might fail and point you in the direction of the error. >> >>>>> Regards, >> >>>>> Søren >> >> >>>>> On Mon, Mar 16, 2009 at 7:03 PM, Stephan Beal >> >>>>> <[email protected]> >> >>>> wrote: >> >> >>>>>> On Mon, Mar 16, 2009 at 6:56 PM, <[email protected]> wrote: >> >>>>>>> The only time I call SetAccessor is to create function >> >>>>>>> templates and >> >>>>>>> bind C++ calls to them. Do you think this could happen during >> >>>>>>> runtime >> >>>>>>> when creating an array in C++ and sending into script? >> >> >>>>>> It's theoretically possible, sure. v8 is quite fussy about >> >>>>>> certain >> >>>>>> things. For example, calling Object::Cast(*myHandle) will crash >> >>>>>> if >> >>>>>> myHandle is-not-a Object. In my experience, most of the >> >>>>>> harder-to-avoid crashes happen right after main() exits, when >> >>>>>> certain >> >>>>>> objects are trying to destruct after v8 has already gone >> >>>>>> through the >> >>>>>> static destruction phase. >> >> >>>>>> As a test, try something like: >> >> >>>>>> myArray->Set( Integer::Cast(*myHandle) ) >> >> >>>>>> where myHandle is-not-an Integer. It "should" (in my >> >>>>>> experience) crash >> >>>>>> there. Are you using: >> >> >>>>>> myArray->Set( Integer::New(...), ...) >> >> >>>>>> or the former form? (The latter should, in theory, not be a >> >>>>>> problem >> >>>>>> unless you just happen to use whatever number v8 reserves for >> >>>>>> NaN(???).) >> >> >>>>>> -- >> >>>>>> ----- stephan beal >> >>>>>>http://wanderinghorse.net/home/stephan/ > > > -- Erik Corry, Software Engineer Google Denmark ApS. CVR nr. 28 86 69 84 c/o Philip & Partners, 7 Vognmagergade, P.O. Box 2227, DK-1018 Copenhagen K, Denmark. --~--~---------~--~----~------------~-------~--~----~ v8-users mailing list [email protected] http://groups.google.com/group/v8-users -~----------~----~----~----~------~----~------~--~---
