Protocol buffers & memory leaks

35 views
Skip to first unread message

Jindrich Sarson

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

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 com.google.j2objc.annotations.AutoreleasePool;
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() {
      @Override
      public void run() {
        periodicTestTask();
      }
    }, 0, 100);
  }

  @AutoreleasePool private void periodicTestTask() {
    PbComm.TestMessage testMessage = PbComm.TestMessage.newBuilder()
     .setNumber(1)
     .build();
    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.

Thanks,

Jindrich

Screenshot 2022-11-29 at 17.15.20.png

Tom Ball

unread,
Nov 29, 2022, 6:30:42 PM11/29/22
to j2objc-...@googlegroups.com
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 j2objc-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/j2objc-discuss/55873516-4d7e-461c-9573-202e436e4766n%40googlegroups.com.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages