Freeing objects used in requests, when using note-c

Hi -
I’m using the note-c library. Let’s say I want to create a Note, to be sent to Notehub. I’ll use something like this:

J *req = NoteNewRequest(“note.add”);
JAddStringToObject(req, “file”, “readings.qo”);

J *rsp = NoteRequestResponseWithRetry(req, 5);

But I have to add a body to the Note. I’m assuming I do that something like this:

J *body = JAddObjectToObject(req, “body”);
JAddNumberToObject(body, “p1”, 12);

But now I’m puzzled. Once I have called:

J *rsp = NoteRequestResponseWithRetry(req, 5);

I understand that “the passed in request object is always freed”, per the note-c documentation, but does the nested object “body” automatically get freed too, or is my code responsible for calling JDelete(body)?

Hello @darkerenergy,

Great question!

The entire Note is freed using JDelete, which performs a recursive deletion of the object (i.e. deletes all child nodes).

Happy hacking,
Zak

1 Like

Hi Zak -

Thanks for the amazingly prompt response! I was kinda hoping that would be the case.

Cheers.

1 Like