Hi,
You only need to call pb_release() on the main message, the same
as you passed to pb_decode(). It releases everything contained there.
If you need to release (or keep) the submessages individually,
you should then remove them from the main message array (set its count to 0).
--
Petteri
> >>>>>> *1. Specify max_count*
> >>>>>> If you know in ahead a maximum number of items in the repeated
> >>>>>> arrays, you can specify it as max_count:
> >>>>>>
> >>>>>> import 'nanopb.proto';
> >>>>>> ...
> >>>>>> repeated AppTeamInfo.Member members = 2 [(nanopb).max_count = 10];
> >>>>>>
> >>>>>> Then you get a regular C array which you can access.
> >>>>>>
> >>>>>> *2. Use dynamic allocation (PB_ENABLE_MALLOC)*
> >>>>>> Then malloc() is used to allocate the memory.
> >>>>>>
> >>>>>> *3. Use callback functions*
> --
> You received this message because you are subscribed to the Google Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
nanopb+un...@googlegroups.com.
> To view this discussion visit
https://groups.google.com/d/msgid/nanopb/349d2419-02e8-4821-a5bf-9b4043c6cae4n%40googlegroups.com.
> I am looking at using pb_release as you suggested.
> I am calling release for each of the member objects I receive. This
> works well as per:
>
> pb_release(rustplus_AppTeamInfo_Member_fields,&member);
>
> After that, I then attempt to release the teaminfo object as well, but
> that causes the esp32 to crash. The line in question is:
>
> rustplus_AppTeamInfo team = response.response.teamInfo;
>
> int members = team.members_count;
> Serial.printf("Team size is: %i",members);
> for(int i=0;i<members;i++){
> _rustplus_AppTeamInfo_Member member = team.members[i];
> player_online(
member.name,member.isOnline);
> pb_release(rustplus_AppTeamInfo_Member_fields,&member);
> }
> pb_release(rustplus_AppTeamInfo_fields,&team); ------- THIS LINE
>
> Any ideas why this is crashing the application? Is it because this gets
> tidied automatically? I suppose I just used malloc for the members
> array, and the name variables, both of which are tidied by pb_release
> of &member?
>
> Maybe thats enough?
>
> On Monday, 10 February 2025 at 14:57:58 UTC Renegade wrote:
>
> Scratch that - I made a mistake. It's absolutely working - thank
> you!
>
> On Monday, 10 February 2025 at 14:23:23 UTC [1]
petteri...@gmail.com
> See [2]
https://jpa.kapsi.fi/nanopb/docs/concepts.html#field-callbacks
> --
> You received this message because you are subscribed to the Google
> Groups "nanopb" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [3]
nanopb+un...@googlegroups.com.
> To view this discussion visit
> [4]
https://groups.google.com/d/msgid/nanopb/349d2419-02e8-4821-a5bf-9b4
> 043c6cae4n%
40googlegroups.com.
>
> References
>
> 1. file:///tmp/neomutt.html
> 2.
https://jpa.kapsi.fi/nanopb/docs/concepts.html#field-callbacks
> 3. mailto:
nanopb+un...@googlegroups.com
> 4.
https://groups.google.com/d/msgid/nanopb/349d2419-02e8-4821...@googlegroups.com?utm_medium=email&utm_source=footer