Skip to content

Protobuf memory leaks - SINGULAR_SETTER_IMP #2410

Open
@sarsonj

Description

@sarsonj

Hi,

we finally decided to update j2objc from very old version 2.8 to current master. During our profiling tests we realised, that after update, there is many memory leaks related to protobuffers. Because we are using protobuffers for inter device communication and we are sending relative big amount of data through them, this is major issue for us.

I went backwards through all changes in protobuf runtime, until I found change, that was implemented in commit 9e9614f . Specifically, the macro:

#define SINGULAR_SETTER_IMP(NAME) \
  static void SingularSet##NAME(id msg, TYPE_##NAME value, size_t offset, CGPHasLocator hasLoc) { \
    TYPE_##NAME *ptr = FIELD_PTR(TYPE_##NAME, msg, offset); \
    ClearPreviousOneof(msg, hasLoc, (uintptr_t)ptr); \
    TYPE_ASSIGN_##NAME(*ptr, value); \
    SetHas(msg, hasLoc); \
  }

that was changed in this commit to:

#define SINGULAR_SETTER_IMP(NAME) \
  static void SingularSet##NAME(id msg, TYPE_##NAME value, size_t offset, CGPHasLocator hasLoc) { \
    TYPE_##NAME *ptr = FIELD_PTR(TYPE_##NAME, msg, offset); \
    ClearPreviousOneof(msg, hasLoc, (uintptr_t)ptr); \
    TYPE_RETAINED_ASSIGN_##NAME(*ptr, value); \
    SetHas(msg, hasLoc); \
  }

seems to causing the memory leaks.

When I changed TYPE_RETAINED_ASSIGN back to TYPE_ASSIGN, memory leaks disappeared.

The screenshot from profiler:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions