Skip to content

Reset reference counter to fix memory leak#350

Closed
PhilWun wants to merge 1 commit intogodotengine:masterfrom
PhilWun:fix_memory_leak
Closed

Reset reference counter to fix memory leak#350
PhilWun wants to merge 1 commit intogodotengine:masterfrom
PhilWun:fix_memory_leak

Conversation

@PhilWun
Copy link

@PhilWun PhilWun commented Nov 22, 2019

This needs to be merged after godotengine/godot-headers#60 is merged.
This is part of the fix for #215.

@BastiaanOlij
Copy link
Collaborator

Not sure if this is safe in all conditions... Need some more opinions

@BastiaanOlij BastiaanOlij requested review from BastiaanOlij and akien-mga and removed request for BastiaanOlij January 30, 2020 10:01
@BastiaanOlij BastiaanOlij added the bug This has been identified as a bug label Jan 30, 2020
script->set_library(godot::get_wrapper<godot::GDNativeLibrary>((godot_object *)godot::gdnlib)); \
script->set_class_name(#Name); \
Name *instance = godot::as<Name>(script->new_()); \
godot::Reference *ref = (godot::Reference *)instance; \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not use C-style cast. This will "always succeed", even when instance isn't a reference, resulting in undefined behavior. Use Object::cast_to instead.

Name *instance = godot::as<Name>(script->new_()); \
godot::Reference *ref = (godot::Reference *)instance; \
if (ref) { \
ref->reset_ref(); \
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does reset_ref() come from? I don't see it in Reference.

@Zylann
Copy link
Collaborator

Zylann commented Jun 5, 2020

Should no longer be needed after #408

@Zylann
Copy link
Collaborator

Zylann commented Aug 14, 2020

Closing since the cause of the leak was fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

archived bug This has been identified as a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants