godotengine / godotengine/godot

Android GodotPlugin emitSignal seems to be leaking memory

Open
#90,650 0 comments 0 reactions 0 assignees View on GitHub
bug platform:android topic:core
Dominant language
C++
Stars
117k
Forks
26.8k
PR merge metrics
PR metrics pending

Description

### Tested versions

- Reproducible using maven dependency `org.godotengine:godot:4.2.1.stable`

### System information

Android SDK 28-32 at least, Godot 4.2.1, emulator, and real hardware, Compatibility mode

### Issue description

Sending a large image as a bytearray via the emitSignal mechanism causes a noticeable memory increase that never is deallocated.

I think it is a general issue with `emitSignal`, no matter the type of data sent but no evidence besides the one with the large bytearray.

### Steps to reproduce

call `GodotPlugin.emitsignal` passing a large bytearray as parameter. with the android profiler running, try to force a GC notice the memory does not go down.

![image](https://github.com/godotengine/godot/assets/1908065/8bd34d3a-f6c6-4058-8b83-06e353ecf8ad)

The bumps in the image are caused by the emit signal function called on a button handler (pink dot) the GC event was forced, notice nothing was collected.

_Update_

Calling `PackedArray.clear` on GDScript side reduces de memory consumption, but I think the reference is still alive and will not be collected.

### Minimal reproduction project (MRP)

[empty-godot-project-main.zip](https://github.com/godotengine/godot/files/14969352/empty-godot-project-main.zip)

also put on a [repo](https://github.com/spacetug/empty-godot-project)

Contributor guide

Open the contributing guide

Research direction

Start with the attached minimal reproduction project and Android profiler, invoking GodotPlugin.emitSignal with a large bytearray and forcing GC. Trace the emitSignal path and compare memory after PackedArray.clear; done means the large allocation is released after collection.

Written by the indexing model from the issue text.

Assessment

Tech stack
android
Domain
mobile
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.