Cool. Excellent explanation Cory...

Could you guys possibly point out these API methods that have to do
with memory and the GC as the environment that V8 is running is
tightly memory constrained and it would be nice to be able to control
that. Ive been searching through the source, but cant seem to find
these methods int he api. Thanks.

On Mar 17, 9:42 am, Alex Iskander <[email protected]> wrote:
> Unfortunately, you cannot specifically tell v8 to run a global gc  
> (unless, I think, you compile with specific settings; under this  
> situation you may call gc from JavaScript). This is usually not a  
> problem when the context ends and the program ends immediately  
> afterwards. Nor is it usually a problem if you have many contexts,  
> since the garbage collection would still occur automatically when v8  
> thought it was best. It CAN cause a problem, however, if these objects  
> are tied to native C++ objects which are connected to resources such  
> as file system resources, etc., that need to be explicitly closed. In  
> these situations, the objects have to be manually destroyed.
>
> I've never used them, but there are some settings you can call to tell  
> v8 how much space it can use. The only thing I do use is the function  
> to tell JavaScript how much external memory it is keeping allocated  
> through its allocation of JavaScript objects (for instance, assume you  
> allocate an image in JavaScript; the JavaScript structure may be a few  
> bytes, but the C++ structure may be a few megabytes).
>
> I don't know if there is a true limit on the amount of space, nor what  
> v8 will do if it reaches such a limit. My understanding was that it  
> would just garbage collect more often the more memory is being used.
>
> Alex
>
> On Mar 17, 2009, at 9:21 AM, MJ wrote:
>
>
>
>
>
> > 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
> > 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?
>
> > 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/
>
> Alex Iskander, TPSi
--~--~---------~--~----~------------~-------~--~----~
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
-~----------~----~----~----~------~----~------~--~---

Reply via email to