Index: src/heap.h |
=================================================================== |
--- src/heap.h (revision 2740) |
+++ src/heap.h (working copy) |
@@ -629,7 +629,7 @@ |
// Performs a full garbage collection. Force compaction if the |
// parameter is true. |
- static void CollectAllGarbage(bool force_compaction = false); |
+ static void CollectAllGarbage(bool force_compaction); |
// Performs a full garbage collection if a context has been disposed |
// since the last time the check was performed. |
@@ -839,6 +839,33 @@ |
> old_gen_allocation_limit_; |
} |
+ // Can be called when the embedding application is idle. |
+ static bool IdleNotification() { |
+ static const int kIdlesBeforeCollection = 7; |
+ static int number_idle_notifications = 0; |
+ static int last_gc_count = gc_count_; |
+ |
+ bool finished = false; |
+ |
+ if (last_gc_count == gc_count_) { |
+ number_idle_notifications++; |
+ } else { |
+ number_idle_notifications = 0; |
+ last_gc_count = gc_count_; |
+ } |
+ |
+ if (number_idle_notifications >= kIdlesBeforeCollection) { |
+ bool force_compaction = true; |
+ CollectAllGarbage(force_compaction); |
+ number_idle_notifications = 0; |
+ finished = true; |
+ } |
+ |
+ // Uncommit unused memory in new space. |
+ Heap::UncommitFromSpace(); |
+ return finished; |
+ } |
+ |
private: |
static int semispace_size_; |
static int initial_semispace_size_; |