On Thu, May 6, 2010 at 11:54 PM, Camilo Aguilar <[email protected]>wrote:
> Thank you for your quick answers but what happens if I have a library like > libxml, gnutls, c-ares, libvirt, etc. They have theirs own internal memory > allocations and deallocations. Does this affect the v8 garbage collection > heuristics? Not directly, no. v8 cannot know how much memory libexpat, curses, etc. allocate for themselves, and the AdjustAmountOfExternalAllocatedMemory() API (try typing that 10 times quickly) is there so we can give v8 a hint about how much we've allocated. For bound C++ types i sometimes add a member, something like "memoryUsage()", which i can use for this purpose, but it is important that you pass the same relative value to AAoEAAM() when incrementing/decrementing the value, to avoid that the allocation hints end up out of sync. Unless v8 and all bound funcs/classes use the same allocator, there really is no in-language way of knowing how much memory is in use by each component. When importing other libs, which may in fact use their own allocators, the best we can do is guess and give v8 that number. Keep in mind that in C++ library authors can re-implement the 'new' operator, which means that (in theory, though not in practice) a library with 100 classes _could_ use 100 different allocation sources. That said, for "most" desktop purposes, it's not critical to make v8 aware of memory used by the internals of 3rd-party code. > I need to hack each library that I want to use through Javascript to add > AdjustAmountOfExternalAllocatedMemory in everyone of them? > If you _need_ that feature, yes. In my experience, though, it's not critical. -- ----- stephan beal http://wanderinghorse.net/home/stephan/ -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
