From 00120a885be88e40446b8acee27e6b311d23f233 Mon Sep 17 00:00:00 2001 From: atomizer Date: Sun, 15 May 2011 02:27:29 +0400 Subject: [PATCH 1/2] make v8 more aware of memory allocations --- src/Canvas.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index b7fee0c..6462517 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -294,6 +294,7 @@ Canvas::Canvas(int w, int h): ObjectWrap() { width = w; height = h; _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); + V8::AdjustAmountOfExternalAllocatedMemory(4 * width * height); } /* @@ -313,7 +314,7 @@ Canvas::resurface(Handle canvas) { // Re-surface cairo_surface_destroy(_surface); _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - V8::AdjustAmountOfExternalAllocatedMemory(-4 * width * height); + V8::AdjustAmountOfExternalAllocatedMemory(4 * width * height); // Reset context Handle context = canvas->Get(String::New("context")); From 6f08e9e6c84a737694fa5b87256ef538beb18289 Mon Sep 17 00:00:00 2001 From: atomizer Date: Sun, 15 May 2011 04:20:56 +0400 Subject: [PATCH 2/2] proper memory adjust when resizing --- src/Canvas.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Canvas.cc b/src/Canvas.cc index 6462517..cd3dedb 100644 --- a/src/Canvas.cc +++ b/src/Canvas.cc @@ -312,9 +312,11 @@ Canvas::~Canvas() { void Canvas::resurface(Handle canvas) { // Re-surface + int old_width = cairo_image_surface_get_width(_surface); + int old_height = cairo_image_surface_get_height(_surface); cairo_surface_destroy(_surface); _surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height); - V8::AdjustAmountOfExternalAllocatedMemory(4 * width * height); + V8::AdjustAmountOfExternalAllocatedMemory(4 * (width * height - old_width * old_height)); // Reset context Handle context = canvas->Get(String::New("context"));