should I delete pointers at end of loop to prevent running out of memory?

Hi,

I have create pointers inside a loop. I believe my program runs out of memory as I get a memory segmentation fault.

Should I be deleting the pointers at the end of the loop? and how do you do this?

Thanks

void loop() {
 


//write to file

}

I get a memory segmentation fault.

What are you running this on?

How do you know you are getting a a memory segmentation fault?

The pointers you have declared in the loop() function are deleted automatically as soon as you exit the loop function, so there is no need to do anything. However, I fail to understand what this code is doing, as you are passing a NULL string pointer to those functions:

 char* sqnum = strtok(NULL, ":");
 char* vcap = strtok(NULL, ":");
 char* vbat = strtok(NULL, ":");
 char* distance = strtok(NULL, ":");

No you definitely do not delete them. They are just pointing to somewhere in the middle of sx1272.packet_received.data.

However, I fail to understand what this code is doing, as you are passing a NULL string pointer to those functions:

That part is OK, that is how strtok works.

Personally I would be testing those pointers before using them, because if the string you are parsing does not have enough ":" in it, the pointers will be NULL, and the sprintf will fail.

Plus, how big is buffer1?

http://snippets-r-us.com/

The pointers you have declared in the loop() function are deleted automatically as soon as you exit the loop function, so there is no need to do anything.

Keep in mind that strtok() is not allocating space for the pointer. It is making the pointer point to somewhere in the string being parsed. So, there is no reason to, and no way to, delete the pointers, and no need to free the memory pointed to by the pointer.

You don't delete pointers. You delete objects. Since you're not creating an object in the code you have posted, you don't have to delete anything.