[v17.3] - Clear 4D-Oject

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[v17.3] - Clear 4D-Oject

4D Tech mailing list
G’day,

Is there a simpler way to clear/destroy a 4D-Object than to loop trough it?

I think of something already implemented in ObjectTools - OT Clear(ObjHandle) / OT Clear (All)

Thanks

Cheers
Jörg
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: [v17.3] - Clear 4D-Oject

4D Tech mailing list
Clear variable?

> On Sep 23, 2019, at 5:01 PM, Jörg Knebel via 4D_Tech <[hidden email]> wrote:
>
> G’day,
>
> Is there a simpler way to clear/destroy a 4D-Object than to loop trough it?
>
> I think of something already implemented in ObjectTools - OT Clear(ObjHandle) / OT Clear (All)
>
> Thanks
>
> Cheers
>

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

RE: [v17.3] - Clear 4D-Oject

4D Tech mailing list
In reply to this post by 4D Tech mailing list
Clear Variable (object)  ???

Randy Engle

-----Original Message-----
From: 4D_Tech <[hidden email]> On Behalf Of Jörg Knebel via 4D_Tech
Sent: Monday, September 23, 2019 5:02 PM
To: 4D Tech Mailing List Technical <[hidden email]>
Cc: Jörg Knebel <[hidden email]>
Subject: [v17.3] - Clear 4D-Oject

G’day,

Is there a simpler way to clear/destroy a 4D-Object than to loop trough it?

I think of something already implemented in ObjectTools - OT Clear(ObjHandle) / OT Clear (All)

Thanks

Cheers
Jörg
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: [v17.3] - Clear 4D-Oject

4D Tech mailing list


> On 24 Sep 2019, at 10:21 AEST, Randy Engle via 4D_Tech <[hidden email]> wrote:
>
> Clear Variable (object)

Arrrgh, that’s it - Thanks
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: [v17.3] - Clear 4D-Oject

4D Tech mailing list
Jörg,

I would suggest you use New Object again, assuming you want the object
to still exist but just be empty.

C_OBJECT($MyObject_o;$MyOtherObject_o)
$MyObject_o:=New object("Wombats";"Are Cute")
$MyOtherObject_o:=New object("Echidnas";"Are NOT cuddly")

$MyObject_o:=New object
//  $MyObject_o is {}

CLEAR VARIABLE($MyOtherObject_o)
//  $MyOtherObject_o is Null

$MyOtherObject_o.Platypodes:="Are also egg laying monotremes"
//  This will give an error Undefined Object

$MyObject_o.Koalas:="Are the Wombats of the trees."
//  This won't give an error

Regards,

Wayne



On Tue, 24 Sep 2019 at 10:27, Jörg Knebel via 4D_Tech
<[hidden email]> wrote:

>
>
>
> > On 24 Sep 2019, at 10:21 AEST, Randy Engle via 4D_Tech <[hidden email]> wrote:
> >
> > Clear Variable (object)
>
> Arrrgh, that’s it - Thanks
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: [v17.3] - Clear 4D-Oject

4D Tech mailing list
In reply to this post by 4D Tech mailing list
I thought that only clears a reference to the object, not the object itself.

Reiner Kief
Germany


> Am 24.09.2019 um 02:15 schrieb Lee Hinde via 4D_Tech <[hidden email]>:
>
> Clear variable?

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: [v17.3] - Clear 4D-Oject

4D Tech mailing list
> I thought that only clears a reference to the object, not the object itself.

Depends,

if the ref-counter goes to 0, the object itself will be cleared too.
--

Grüße/Regards,
[heubach-media] | Christian Sakowski
[hidden email]
Tel: +49/(0)40/41 455 455





> Am 24.09.2019 um 08:33 schrieb Reiner Kief via 4D_Tech <[hidden email]>:
>
> I thought that only clears a reference to the object, not the object itself.
>
> Reiner Kief
> Germany
>
>
>> Am 24.09.2019 um 02:15 schrieb Lee Hinde via 4D_Tech <[hidden email]>:
>>
>> Clear variable?
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive:  http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub:  mailto:[hidden email]
> **********************************************************************


--
heubach media
Osterfeldstr. 12-14 | Haus 1 | Eingang Nord
22529 Hamburg
tel: 040 / 52 10 59 - 10 | fax: -99
mail: [hidden email]
home: www.heubach-media.de
Geschäftsführer|CEO: Matthias Heubach

Mieten Sie Ihre Computer, iPads & Drucker für Ihre Events bei:
http://www.milo-rental.com

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: [v17.3] - Clear 4D-Oject

4D Tech mailing list
On Mon, Sep 23, 2019 at 11:42 PM Christian Sakowski via 4D_Tech <
[hidden email]> wrote:

> > I thought that only clears a reference to the object, not the object
> itself.
>
> Depends,
>
> if the ref-counter goes to 0, the object itself will be cleared too.
>
That's why I prefer Wayne's suggestion of using New object. Or setting it
to null.
But the lesson here is keeping in mind exactly what it is you are trying to
do.

$root:=New object("a";100;"details";New object("b";200;"c";"foo"))
$child:=$root.details
$child.d:="bar"  // root: {a:100,details:{b:200,c:foo,d:bar}}
CLEAR VARIABLE($root)  // $root = null; $child: {b:200,c:foo,d:bar}

 // --------------------------------------------------------
$root:=New object("a";100;"details";New object("b";200;"c";"foo"))
$child:=$root.details
$child.d:="bar"  // root: {a:100,details:{b:200,c:foo,d:bar}}

$root:=New object  // $root = {}; $child: {b:200,c:foo,d:bar}

In both cases $child persists because the object itself ($child) exists
with its own ref counter. This may or may not be what you want.
What do you think happens when $child:=New object?

 // --------------------------------------------------------
$root:=New object("a";100;"details";New object("b";200;"c";"foo"))
$child:=$root.details
$child.d:="bar"  // root: {a:100,details:{b:200,c:foo,d:bar}}

$child:=New object  // $root = {a:100,details:{b:200,c:foo,d:bar}}; $child:
{}

How the hell do I make $child and $root.details be empty? Maybe:
   // --------------------------------------------------------
$root:=New object("a";100;"details";New object("b";200;"c";"foo"))
$child:=$root.details
$child.d:="bar"  // root: {a:100,details:{b:200,c:foo,d:bar}}
$root.details:=New object // $root = {a:100,details:{}}; $child:
{b:200,c:foo,d:bar}

Why doesn't $child become empty? It's in the docs: "... New object creates
an empty object and returns its reference." $root.details contained a
reference, because the data are actually stored and managed by 4D, to the
object created by the first call to New object. Next I assigned $child the
reference to that same object. So its ref count is now 2. When I
call $root.details:=New object a new ref is created and assigned to
$root.details. This also lowers the ref count for the original object from
2 to 1. Because the ref count is not 0 the data persists and so $child,
which actually is a reference to the original object, still 'has' the
data.

This is what we encounter when using Storage too. Each object has to be
tracked with respect to its ref counter. That's why it's so fussy about
only allowing other shared objects to mingle.

This is a much different way of thinking about data outside of records and
fields or variables. In those cases the object is the data, as it were. And
this makes a strong case for scoping objects as local vars as much as
feasible because when a method ends the local vars are destroyed and any
references assigned only to local vars are cleared.

Here's a final take on this example. In this case let's define $child first:
   // --------------------------------------------------------
$child:=New object("b";200;"c";"foo")
$root:=New object("a";100;"details";$child)
$joey:=$root.details    what's the ref count on $child now?

$joey.d:="bar"  // root: {a:100,details:{b:200,c:foo,d:bar}}

For each ($prop;$root.details)

OB REMOVE($root.details;$prop)

End for each
// $root: {a:100,details:{}}  , $child: {},  $joey: {}

I hope this helps. It's been a real challenge for me to get the hang of how
references work and I don't profess to be an expert at it.

BTW - I did those examples in 17r6 but they should be the same in any
previous version.

--
Kirk Brooks
San Francisco, CA
=======================

What can be said, can be said clearly,
and what you can’t say, you should shut up about

*Wittgenstein and the Computer *
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

RE: [v17.3] - Clear 4D-Oject

4D Tech mailing list
In reply to this post by 4D Tech mailing list
> Is there a simpler way to clear/destroy a 4D-Object than to loop trough it?

Unless it has circular references, there is no need to explicitly clear it. It will be cleared automatically when the variable goes out of scope.

If there are circular references, they should be set to null.

$a:=New object
$b:=New object(“a”;$a)
$a.b:=$b

// use them

// At end of method
$a.b:=null


> How the hell do I make $child and $root.details be empty?

You don’t. There’s no need to. Even if you are reassigning to a new object, there is absolutely no need to clear first.

- Aparajita
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************