Icon View Thread

The following is the text of the current message along with any replies.
Messages 11 to 20 of 25 total
Thread Freeing component and subsequent Assigned checking
Wed, Jan 6 2016 9:01 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Sounds like you fixed that one the wrong way around. Removing "with" would have been better.  8-) >>

Smile Unfortunately (or fortunately), "with" is very valuable with the emitted JS because it keeps the size smaller.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Jan 6 2016 9:51 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> the emitted JS because it keeps the size smaller.

Is that not something the optimiser can do anyway? If I do

object.blah := 3;
object.boop := 4;
object.bump := 5;

is that optimised, or would it really help to use
with object do
...

I don't think I'd change most code, but if significant then in some
loops it might be worth doing. The optimiser would be a better place
(long time since I wrote a compiler mind, so maybe things are different
to the DAG's I used to make).

--

Matthew Jones
Wed, Jan 6 2016 11:11 AMPermanent Link

Raul

Team Elevate Team Elevate

On 1/6/2016 9:51 AM, Matthew Jones wrote:
> Is that not something the optimiser can do anyway? If I do
>
>   object.blah := 3;
>   object.boop := 4;
>   object.bump := 5;
>
> is that optimised, or would it really help to use
>   with object do
>   ...

I'm no expert but this starts to look fishy to me - optimizer is now
changing the actual source code itself. There are various way this could
mess up things and it would be invisible to you (developer) if you get a
weird error since code looks right.

Raul
Wed, Jan 6 2016 11:16 AMPermanent Link

Raul

Team Elevate Team Elevate

On 1/6/2016 11:11 AM, Raul wrote:
> I'm no expert but this starts to look fishy to me - optimizer is now
> changing the actual source code itself. There are various way this could
> mess up things and it would be invisible to you (developer) if you get a
> weird error since code looks right.

Never mind - i misread the original so this does not apply at all.

let's see what Tim says about how (much) the with optimization would helps.

Raul
Wed, Jan 6 2016 11:23 AMPermanent Link

Raul

Team Elevate Team Elevate

On 1/5/2016 2:39 PM, Trinione wrote:
> When I do it this way I get an instant error every time.

That means your object has been freed and/or already assigned nil value.

in general you want object creation and destruction to be deterministic
- for example in constructor/destructor or form create/destroy -  but if
there are number of ways it could be allocated or freed then you should
adopt the nil and assign pattern:

- when creating use :
if not assigned(myinstance) then  myinstance := TMyINstance.Create ....

This ensure you don't create extra instances and lose reference to them.

- when freeing use
if assigned(myinstance) then
begin
 myinstance.Free;
 myinstance := nil;
end;

JS does use garbage collection so you "get away with it" in terms of not
leaking runtime memory otherwise but you could still introduce bugs of
course.

> I am calling it after an animation when I move the form off the screen. Putting nil first is the only way it works.

Are you actually moving the form or freeing it? Any chance one of the
form events either frees or assigns nil during this move?

Raul
Wed, Jan 6 2016 12:32 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Is that not something the optimiser can do anyway? If I do

object.blah := 3;
object.boop := 4;
object.bump := 5;

is that optimised, or would it really help to use
with object do >>

The compiler does not combine statements into "with" blocks for one reason:  certain JS engines like Chrome's V8 engine *specifically* don't optimize a "with" statement.  So, I want to leave the ability to "reduce the code" for developers, but don't want to remove my ability to specifically leave out a with. Smile

If you look at this method in the WebUI unit:

procedure TElement.ApplyStyle(AChanges: TSet;
                             ASelective: Boolean=True);

You'll see a little note from me about this.

The other thing to keep in mind is that the compiler's compression will most likely trim down the first example to something like this:

a1.b2 = 3;
a1.b2 = 4;
a1.b2 = 5;

or even smaller, depending upon the identifiers being used.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Jan 7 2016 4:27 AMPermanent Link

Matthew Jones

Tim Young [Elevate Software] wrote:

> The compiler does not combine statements into "with" blocks for one
> reason:  certain JS engines like Chrome's V8 engine specifically
> don't optimize a "with" statement.

Of course - seems odd to be producing output that is then compiled
itself, and of course that compiler can then do the optimisations. How
things have changed in the world of computers!

--

Matthew Jones
Thu, Jan 7 2016 11:15 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Of course - seems odd to be producing output that is then compiled itself, and of course that compiler can then do the optimisations. How things have changed in the world of computers! >>

It's compilers all the way down. Smile

https://en.wikipedia.org/wiki/Turtles_all_the_way_down

Things are about to get a little more optimized as we are starting to hit the limits of physics, atoms and speed of light and all, but JS optimization still has room to improve before it starts to run into being as fast as native.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Feb 18 2016 8:51 AMPermanent Link

Trinione

I can check if it is assigned and Free it before creation, but how can it be Freed on form close?

Thanks.
Thu, Feb 18 2016 8:53 AMPermanent Link

Trinione

In the Close event I can say:

Free;

However, I can't put the

Free;
Self := nil;
« Previous PagePage 2 of 3Next Page »
Jump to Page:  1 2 3
Image