Skip to content

Commit 31d6176

Browse files
committed
[webview_flutter] Fix memory issue
Signed-off-by: MuHong Byun <[email protected]>
1 parent b2b2035 commit 31d6176

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

packages/webview_flutter/tizen/src/webview.cc

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ WebView::WebView(flutter::PluginRegistrar* registrar, int viewId,
167167
is_mouse_lbutton_down_(false),
168168
has_navigation_delegate_(false),
169169
has_progress_tracking_(false),
170-
context_(nullptr) {
170+
context_(nullptr),
171+
texture_variant_(nullptr),
172+
gpu_buffer_(nullptr) {
171173
texture_variant_ = new flutter::TextureVariant(flutter::GpuBufferTexture(
172174
[this](size_t width, size_t height) -> const FlutterDesktopGpuBuffer* {
173175
return this->CopyGpuBuffer(width, height);
@@ -393,6 +395,11 @@ void WebView::Dispose() {
393395
delete texture_variant_;
394396
texture_variant_ = nullptr;
395397
}
398+
399+
if (gpu_buffer_) {
400+
delete gpu_buffer_;
401+
gpu_buffer_ = nullptr;
402+
}
396403
}
397404

398405
void WebView::Resize(double width, double height) {
@@ -759,6 +766,10 @@ void WebView::InitWebView() {
759766
webview_instance_->Destroy();
760767
webview_instance_ = nullptr;
761768
}
769+
if (!gpu_buffer_) {
770+
gpu_buffer_ = new FlutterDesktopGpuBuffer();
771+
}
772+
762773
float scale_factor = 1;
763774

764775
webview_instance_ = (LWE::WebContainer*)createWebViewInstance(
@@ -925,11 +936,12 @@ FlutterDesktopGpuBuffer* WebView::CopyGpuBuffer(size_t width, size_t height) {
925936
rendered_surface_ = candidate_surface_;
926937
candidate_surface_ = nullptr;
927938

928-
FlutterDesktopGpuBuffer* gpu_buffer = new FlutterDesktopGpuBuffer();
929-
gpu_buffer->buffer = rendered_surface_;
930-
gpu_buffer->width = width;
931-
gpu_buffer->height = height;
932-
return gpu_buffer;
939+
if (gpu_buffer_) {
940+
gpu_buffer_->buffer = rendered_surface_;
941+
gpu_buffer_->width = width;
942+
gpu_buffer_->height = height;
943+
}
944+
return gpu_buffer_;
933945
}
934946

935947
void WebView::DestructBuffer(void* buffer) {

packages/webview_flutter/tizen/src/webview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class WebView : public PlatformView {
7676
std::unique_ptr<flutter::MethodChannel<flutter::EncodableValue>> channel_;
7777
Ecore_IMF_Context* context_;
7878
flutter::TextureVariant* texture_variant_;
79+
FlutterDesktopGpuBuffer* gpu_buffer_;
7980
std::mutex mutex_;
8081
};
8182

0 commit comments

Comments
 (0)