Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: memory leaks #33

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/render/native/components/component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void NativeComponentMaskInit (JSContext* ctx, JSValue ns);
#define WRAPPED_JS_CLOSE_COMPONENT(COMPONENT,COMPONENT_NAME) \
static JSValue NativeCompCloseComponent(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { \
COMP_REF* s = (COMP_REF*)JS_GetOpaque(this_val, COMPONENT##ClassID); \
lv_obj_del_async(((BasicComponent*)(s->comp))->instance); \
delete (BasicComponent*)(s->comp); \
return JS_UNDEFINED; \
} \
\
Expand Down
15 changes: 9 additions & 6 deletions src/render/native/core/basic/comp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@ void BasicComponent::insertChildBefore(void *child) {
}
};

void BasicComponent::removeChild(void* child) {
lv_obj_del_async((static_cast<BasicComponent*>(child))->instance);
};
void BasicComponent::removeChild(void* child) {};

void BasicComponent::appendChild (void* child) {
static_cast<BasicComponent*>(child)->parent_instance = this->instance;
Expand Down Expand Up @@ -86,7 +84,7 @@ void BasicComponent::setTransition (JSContext* ctx, JSValue obj, lv_style_t* sty
lv_style_prop_t* old_transProps = this->trans_props_map[type];

this->trans_props_map[type] = (lv_style_prop_t*)malloc((len + 1) * sizeof(lv_style_prop_t));

JSValue props = JS_GetPropertyUint32(ctx, obj, 1);
int32_t prop_key;
for(int i=0; i < len; i++) {
Expand Down Expand Up @@ -255,8 +253,13 @@ BasicComponent::~BasicComponent () {
if (ptr2) {
free((lv_coord_t*)(ptr2));
}
// do not del here, remove child will do the action
// lv_obj_del(this->instance);

for(auto &style : style_map) {
lv_style_reset(style.second);
}

lv_obj_remove_event_cb(instance, &BasicComponent::EventCallback);
lv_obj_del(this->instance);
};

void BasicComponent::setAlign (int32_t align_type, int32_t x, int32_t y) {
Expand Down
11 changes: 7 additions & 4 deletions src/render/react/core/reconciler/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const getUid = () => {
const instanceMap = new Map();

export const getInstance = (uid) => {
return instanceMap[uid];
return instanceMap.get(uid);
};

const HostConfig = {
Expand Down Expand Up @@ -53,7 +53,6 @@ const HostConfig = {
workInProgress,
uid,
);
instanceMap[uid] = instance;
return instance;
},
createTextInstance: (
Expand Down Expand Up @@ -124,12 +123,16 @@ const HostConfig = {
commitTextUpdate(textInstance, oldText, newText) {
textInstance.setText(newText);
},
detachDeletedInstance: (instance) => {
unRegistEvent(instance.uid);
instanceMap.delete(instance.uid);
instance.style = null; // Proxy preventing GC
EmixamPP marked this conversation as resolved.
Show resolved Hide resolved
},
removeChild(parent, child) {
parent?.removeChild(child);
unRegistEvent(child.uid);
delete instanceMap[child.uid];
},
commitMount: function (instance, type, newProps, internalInstanceHandle) {
instanceMap.set(instance.uid, instance);
const { commitMount } = getComponentByTagName(type);
return commitMount(instance, newProps, internalInstanceHandle);
},
Expand Down