<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>MCUXpresso IDEのトピックRe: How to Check Memory Leak of Array</title>
    <link>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-Check-Memory-Leak-of-Array/m-p/1020742#M5359</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What you are describing is called "Accessing an array out of bounds", rather than a "memory leak".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A memory leak is when your code does a C &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;malloc()&lt;/SPAN&gt; or a C++ &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;new&lt;/SPAN&gt;, but then doesn't do a &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;free()&lt;/SPAN&gt; or &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;delete&lt;/SPAN&gt; when it is finished with the memory. It is like the memory has "leaked" out of the computer, never to be recovered! Instead, you're describing one array being corrupted by data from another array.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Because your two arrays are declared globally, rather than on the stack or the heap, the size of the stack or the heap is not the cause of your problem. The compiler will reserve enough space for those two arrays, and if it runs out of memory it will give a compiler error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead, it is how your code &lt;EM&gt;uses&lt;/EM&gt; the arrays (especially &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;Buffer&lt;/SPAN&gt;) that is the problem. You don't give a example code, but for instance, if you did the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;char&lt;/SPAN&gt; Buffer&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1362&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;read&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;file&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; Buffer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1536&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;Process&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Buffer&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;// if&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That number &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;1536&lt;/SPAN&gt; above should be &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;sizeof(Buffer)&lt;SPAN style="font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;"&gt;,&lt;/SPAN&gt;&lt;/SPAN&gt; which lets the compiler fill in the number for how many bytes to read into &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;Buffer&lt;/SPAN&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 08 Dec 2019 08:31:08 GMT</pubDate>
    <dc:creator>johnadriaan</dc:creator>
    <dc:date>2019-12-08T08:31:08Z</dc:date>
    <item>
      <title>How to Check Memory Leak of Array</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-Check-Memory-Leak-of-Array/m-p/1020741#M5358</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm using LPC1754 with 128kB flash and RAM of 32kB. I'm using MCUxpresso IDE.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I've used only 37% of RAM while compiling the code. I'm using embedded c language.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've come to know that there's a chance of memoryleak, i.e. values of memory changes abnormally without our consent. Some array gets filled with values of other Array or value.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for eg: I'm using character array of size 1362 and another of size 260&amp;nbsp;&amp;nbsp;declared as following.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;char Buffer[1362]&lt;/STRONG&gt;, which is declared globally.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;char response[260], &lt;/STRONG&gt;which is also declared globally.&lt;/P&gt;&lt;P&gt;sometimes &lt;STRONG&gt;response,&lt;/STRONG&gt; which is cleared by using &lt;STRONG&gt;memset&lt;/STRONG&gt; function, gets filled with some data present in &lt;STRONG&gt;Buffer&lt;/STRONG&gt;. I checked for shortage of array size. which is not seen.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I found the same issue with some other variables&amp;nbsp; too, whose value gets changed without our consent, which is causing serious issue in logic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some points that I'm concerned about are:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. heap and stacksize How to modify the size so that the code works without any issue in memory leak.&lt;/P&gt;&lt;P&gt;2. Array size: Which is&amp;nbsp; not found to give any impact at present. But, would like to know steps to check if the array size is getting filled up.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and Regards,&lt;BR /&gt;Athmesh Nandakumar&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Dec 2019 07:52:38 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-Check-Memory-Leak-of-Array/m-p/1020741#M5358</guid>
      <dc:creator>athmesh_n</dc:creator>
      <dc:date>2019-12-07T07:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Check Memory Leak of Array</title>
      <link>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-Check-Memory-Leak-of-Array/m-p/1020742#M5359</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What you are describing is called "Accessing an array out of bounds", rather than a "memory leak".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;A memory leak is when your code does a C &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;malloc()&lt;/SPAN&gt; or a C++ &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;new&lt;/SPAN&gt;, but then doesn't do a &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;free()&lt;/SPAN&gt; or &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;delete&lt;/SPAN&gt; when it is finished with the memory. It is like the memory has "leaked" out of the computer, never to be recovered! Instead, you're describing one array being corrupted by data from another array.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Because your two arrays are declared globally, rather than on the stack or the heap, the size of the stack or the heap is not the cause of your problem. The compiler will reserve enough space for those two arrays, and if it runs out of memory it will give a compiler error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Instead, it is how your code &lt;EM&gt;uses&lt;/EM&gt; the arrays (especially &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;Buffer&lt;/SPAN&gt;) that is the problem. You don't give a example code, but for instance, if you did the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="language-c line-numbers"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;char&lt;/SPAN&gt; Buffer&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;1362&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;read&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;file&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; Buffer&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="number token"&gt;1536&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    &lt;SPAN class="token function"&gt;Process&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;Buffer&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;// if&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That number &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;1536&lt;/SPAN&gt; above should be &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;sizeof(Buffer)&lt;SPAN style="font-family: Helvetica Neue,Helvetica,Arial,Lucida Grande,sans-serif;"&gt;,&lt;/SPAN&gt;&lt;/SPAN&gt; which lets the compiler fill in the number for how many bytes to read into &lt;SPAN style="font-family: terminal,monaco,monospace;"&gt;Buffer&lt;/SPAN&gt;.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Dec 2019 08:31:08 GMT</pubDate>
      <guid>https://community.nxp.com/t5/MCUXpresso-IDE/How-to-Check-Memory-Leak-of-Array/m-p/1020742#M5359</guid>
      <dc:creator>johnadriaan</dc:creator>
      <dc:date>2019-12-08T08:31:08Z</dc:date>
    </item>
  </channel>
</rss>

