Protocol buffers & memory leaks

Skip to first unread message

Jindrich Sarson

Nov 29, 2022, 11:30:29 AM11/29/22
to j2objc-discuss

I ran instruments on our j2objc based app to check for memory leaks. We are using protocol buffers for multiple purposes in our app - for communication, state persistence or so. What I realised was that every protobuf message was flagged as memory leak in Instruments.

I just made simple .proto and simple Java class to be sure that this is protocol buffers problem and not something else in our app. The simple .proto file:

syntax = "proto3";

package comm;
option java_package = "pb";
option java_outer_classname = "PbComm";

message TestMessage {
string text = 1;
int32 number = 2;

and very simple class, that just creates message 10 times in a second:

import pb.PbComm;

import java.util.Timer;
import java.util.TimerTask;

public class ProtoBuffTest {
  Timer timer;
  public void startTest() {
    timer = new Timer();
    timer.schedule(new TimerTask() {
      public void run() {
    }, 0, 100);

  @AutoreleasePool private void periodicTestTask() {
    PbComm.TestMessage testMessage = PbComm.TestMessage.newBuilder()
    System.out.println("Message size: " + testMessage.getSerializedSize());

We are using arc in java translated files and we are using "--swift-friendly -use-arc --nullability -g --no-package-directories --static-accessor-methods -Xforce-incomplete-java8 -source 8" j2objc params.

Any idea, what may be the reason for those memory leaks? I even tried to use j2objc ver. 2.8 (normally we are using newer j2objc from git), but the problem is still there.



Screenshot 2022-11-29 at 17.15.20.png

Tom Ball

Nov 29, 2022, 6:30:42 PM11/29/22
Are you building the generated proto ObjC files with ARC? That may be the issue, since although our tests verify everything works with ARC, I doubt we've done separate memory profiling with it enabled.

You received this message because you are subscribed to the Google Groups "j2objc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
Reply all
Reply to author
Message has been deleted
0 new messages