Skip to content

Commit 3d81887

Browse files
bwikbsswift-kim
authored andcommitted
Clean up existing instances when updating the platform view (#119)
* Clean up existing instances when updating the platform view * This fix problem that occurs when a view is created on restart with identical view id. * Refactor platform view channel which is related to clean up view resources Signed-off-by: MuHong Byun <[email protected]>
1 parent 97ee76a commit 3d81887

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

shell/platform/tizen/channels/platform_view_channel.cc

+31-4
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,30 @@ PlatformViewChannel::~PlatformViewChannel() {
5252
}
5353

5454
void PlatformViewChannel::Dispose() {
55+
ClearViewInstances();
56+
ClearViewFactories();
57+
}
58+
59+
void PlatformViewChannel::RemoveViewInstanceIfNeeded(int view_id) {
60+
auto it = view_instances_.find(view_id);
61+
if (view_id >= 0 && it != view_instances_.end()) {
62+
auto view_instance = it->second;
63+
view_instance->Dispose();
64+
delete view_instance;
65+
view_instances_.erase(it);
66+
}
67+
}
68+
69+
void PlatformViewChannel::ClearViewInstances() {
5570
// Clean-up view_instances_
5671
for (auto const& [view_id, view_instance] : view_instances_) {
72+
view_instance->Dispose();
5773
delete view_instance;
5874
}
5975
view_instances_.clear();
76+
}
6077

78+
void PlatformViewChannel::ClearViewFactories() {
6179
// Clean-up view_factories_
6280
for (auto const& [view_type, view_factory] : view_factories_) {
6381
view_factory->Dispose();
@@ -124,6 +142,7 @@ void PlatformViewChannel::HandleMethodCall(
124142
FT_LOGI(
125143
"PlatformViewChannel create viewType: %s id: %d width: %f height: %f ",
126144
view_type.c_str(), view_id, width, height);
145+
RemoveViewInstanceIfNeeded(view_id);
127146

128147
EncodableMap values = std::get<EncodableMap>(arguments);
129148
EncodableValue value = values[EncodableValue("params")];
@@ -170,6 +189,17 @@ void PlatformViewChannel::HandleMethodCall(
170189
} else {
171190
result->Error("Can't find view id");
172191
}
192+
} else if (method == "dispose") {
193+
int view_id = -1;
194+
if (std::holds_alternative<int>(arguments)) {
195+
view_id = std::get<int>(arguments);
196+
};
197+
if (view_id < 0 || view_instances_.find(view_id) == view_instances_.end()) {
198+
result->Error("Can't find view id");
199+
} else {
200+
RemoveViewInstanceIfNeeded(view_id);
201+
result->Success();
202+
}
173203
} else {
174204
int view_id = -1;
175205
if (!GetValueFromEncodableMap(arguments, "id", &view_id)) {
@@ -179,10 +209,7 @@ void PlatformViewChannel::HandleMethodCall(
179209

180210
auto it = view_instances_.find(view_id);
181211
if (view_id >= 0 && it != view_instances_.end()) {
182-
if (method == "dispose") {
183-
it->second->Dispose();
184-
result->Success();
185-
} else if (method == "resize") {
212+
if (method == "resize") {
186213
double width = 0.0, height = 0.0;
187214
if (!GetValueFromEncodableMap(arguments, "width", &width) ||
188215
!GetValueFromEncodableMap(arguments, "height", &height)) {

shell/platform/tizen/channels/platform_view_channel.h

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class PlatformViewChannel {
2929
virtual ~PlatformViewChannel();
3030

3131
void Dispose();
32+
void RemoveViewInstanceIfNeeded(int view_id);
33+
void ClearViewInstances();
34+
void ClearViewFactories();
3235

3336
std::map<std::string, std::unique_ptr<PlatformViewFactory>>& ViewFactories() {
3437
return view_factories_;

0 commit comments

Comments
 (0)