<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to "__DELETE" of dynamically created struct</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/96ab7e316a/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/96ab7e316a/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/96ab7e316a/</id><updated>2021-04-18T23:05:42.575000Z</updated><subtitle>Recent posts to "__DELETE" of dynamically created struct</subtitle><entry><title>"__DELETE" of dynamically created struct</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/96ab7e316a/?limit=25#221b/edd6" rel="alternate"/><published>2021-04-18T23:05:42.575000Z</published><updated>2021-04-18T23:05:42.575000Z</updated><author><name>audi0615</name><uri>https://forge.codesys.com/u/audi0615/</uri></author><id>https://forge.codesys.comde5a41af9a1137d2fd777935dbb79327fe62a25e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thank for your reply.&lt;br/&gt;
Actually the stMain has many big sized stSub members (stSub1~stSub1024) and in most cases only 1~2 of them are used depending on user configuration.&lt;br/&gt;
static declaration of sub structs results in more than 500mb memory allocation for them. so this is only for reducing memory usage.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>"__DELETE" of dynamically created struct</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/96ab7e316a/?limit=25#221b" rel="alternate"/><published>2021-04-18T13:10:30.443000Z</published><updated>2021-04-18T13:10:30.443000Z</updated><author><name>sgronchi</name><uri>https://forge.codesys.com/u/sgronchi/</uri></author><id>https://forge.codesys.come1de4add7f0bd192ccc8832e6461ccaa147c2dcd</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;No, it is not deleted.&lt;br/&gt;
But why do you require a struct that has a pointer to struct? Couldn't you just embed stSub in stMain as a member?&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>"__DELETE" of dynamically created struct</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/96ab7e316a/?limit=25#f76d" rel="alternate"/><published>2021-04-17T08:57:37.432000Z</published><updated>2021-04-17T08:57:37.432000Z</updated><author><name>audi0615</name><uri>https://forge.codesys.com/u/audi0615/</uri></author><id>https://forge.codesys.com9a9fadfbd080e8512f695018974c9565fc145489</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi.&lt;/p&gt;
&lt;p&gt;I have two sturcts, stMain and stSub.&lt;/p&gt;
&lt;p&gt;stSub is contained in stMain and both structs are dynamically created using __NEW.&lt;/p&gt;
&lt;p&gt;if I delete stMain, is stSub automatically deleted? or Should i delete stSub first and then delete stMain?&lt;/p&gt;
&lt;p&gt;TYPE stMain :&lt;br/&gt;
STRUCT&lt;br/&gt;
    pstSub: POINTER TO stSub;&lt;br/&gt;
END_STRUCT&lt;br/&gt;
END_TYPE&lt;/p&gt;
&lt;p&gt;TYPE stSub :&lt;br/&gt;
STRUCT&lt;br/&gt;
    xTest: BOOL;&lt;br/&gt;
END_STRUCT&lt;br/&gt;
END_TYPE&lt;/p&gt;
&lt;p&gt;PROGRAM PLC_PRG&lt;br/&gt;
VAR&lt;br/&gt;
    pstMain: POINTER TO stMain;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;IF pstMain = 0 THEN&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;pstMain&lt;/span&gt;:&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;__NEW&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;stMain&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="nv"&gt;pstMain&lt;/span&gt;.&lt;span class="nv"&gt;pstSub&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="k"&gt;THEN&lt;/span&gt;
    &lt;span class="nv"&gt;pstMain&lt;/span&gt;.&lt;span class="nv"&gt;pstSub&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;__NEW&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;stSub&lt;/span&gt;&lt;span class="ss"&gt;)&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;END_IF&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;END_IF&lt;/p&gt;
&lt;p&gt;IF pstMain &amp;lt;&amp;gt; 0 THEN&lt;br/&gt;
    __DELETE(pstMain); //This command also deletes pstSub??&lt;br/&gt;
END_IF&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>