Heap usage don't update when use vPortFree.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Heap usage don't update when use vPortFree.

Jump to solution
1,892 Views
andréluis
Contributor II

Hello, i'm using the MIMXRT1060-EVK. In my project i'm using freeRtos and lwip with the heap_3.c. When i use vPortFree, the value of the heap don't update. There's something I can do to update heap usage?

Tags (1)
0 Kudos
Reply
1 Solution
1,544 Views
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

Hi @andréluis,

 

Heap3 scheme only wraps the standard C library malloc() and free() functions to provide thread safety. In this case, when you use pvPortMalloc(), the function will use malloc() to allocate memory.

It's not like vPortFree() isn't working. It is, but you will not see the change in the Heap and Stack Usage option because as per my understanding, free() doesn't delete nor clear the memory, it only marks the space as available for future malloc() allocations.

You can see this by yourself by allocating memory using pvPortMalloc(), then free it with vPortFree(). Then immediately allocate the same amount of memory, you will see that the Heap and Stack Usage will increase only once and not twice.

For more information regarding this, I would recommend you take a look to the FreeRTOS documentation.

 

I hope this helps.

Regards,

Daniel.

View solution in original post

0 Kudos
Reply
8 Replies
1,878 Views
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

Hi,

 

Could you please help me with the following infromation?

 

What SDK version are you using?

Are you trying a SDK example?

How you are making and verifying the heap change?

If I'm understanding correct you would like to use heap 3, but in your project the heap in use in another one, am I right?

 

Regards,

Daniel.

0 Kudos
Reply
1,819 Views
andréluis
Contributor II

Hi Daniel
What SDK version are you using?
I'm using the SDK 2.14 of MIMXRT1060-EVK

Are you trying a SDK example?
Yes. I'm working with evkbmimxrt1060_lwip_ipv4_ipv6_echo_freertos.

How you are making and verifying the heap change?

I attach an image showing how i making the verify of the heap.

If I'm understanding correct you would like to use heap 3, but in your project the heap in use in another one, am I right?

In my project it's using heap_3.c.

0 Kudos
Reply
1,810 Views
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

Thanks for the reply.

I'm sorry for the misunderstanding, I thought you were trying to change the FreeRTOS Heap implementation.

Is there a specific path to get this behavior? If that's the case, could you please tell me how you are running the example so I can try to replicate it on my side?

 

Regards,

Daniel.

0 Kudos
Reply
1,798 Views
andréluis
Contributor II

Hello Daniel, in the picture attach i put a breakpoint when my application call the vPortFree. In my application, i send to him some blocks, like function blocks of PLC, and the value of my heap increase because the blocks. But, when i remove the blocks from my application, the value of the heap don't decreases, showing the same value. In the pictures i show the value before the dowload of the application, the process of download an application, update the value of the heap, download an empty application and the value of the heap don't change. 

0 Kudos
Reply
1,758 Views
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

In other words, in the evkbmimxrt1060_lwip_ipv4_ipv6_echo_freertos SDK example, when you use vPortFree, you don’t see a change in the heap usage. The heap stays the same, am I correct?

 

Regards,

Daniel.

0 Kudos
Reply
1,692 Views
andréluis
Contributor II

Hello Daniel. Yes. This is the problem. I use vPortFree and the heap usage don't change. 

0 Kudos
Reply
1,545 Views
DanielRuvalcaba
NXP TechSupport
NXP TechSupport

Hi @andréluis,

 

Heap3 scheme only wraps the standard C library malloc() and free() functions to provide thread safety. In this case, when you use pvPortMalloc(), the function will use malloc() to allocate memory.

It's not like vPortFree() isn't working. It is, but you will not see the change in the Heap and Stack Usage option because as per my understanding, free() doesn't delete nor clear the memory, it only marks the space as available for future malloc() allocations.

You can see this by yourself by allocating memory using pvPortMalloc(), then free it with vPortFree(). Then immediately allocate the same amount of memory, you will see that the Heap and Stack Usage will increase only once and not twice.

For more information regarding this, I would recommend you take a look to the FreeRTOS documentation.

 

I hope this helps.

Regards,

Daniel.

0 Kudos
Reply
1,170 Views
andréluis
Contributor II
Hi Daniel, in my application, i need to calculate how much a block consume when i select it in the program. That's why i need to use the free, because if i remove a block, i need to calculate how much RAM became free. That's a way to change the free() function?
0 Kudos
Reply