Jump to content
Sign in to follow this  
mewindy

10.3 vers 10.2 Linux

Recommended Posts

HI

I see that Delphi 10.3 has done away with ARC on Linux?

now my program is throwing random access violations that I am struggling to figure  out why

the same code does not do that , on linux, when compiled with Delphi 10.2 instead of 10.3 (I think 10.2 had ARC for linux)?

Q: should I be using disposeof instead of free under linux with 10.3 ?

Share this post


Link to post

Use classic memory management. 

 

obj := TMyObject.Create;

try

  obj.DoSomething;

finally

  obj.Free;

end;

Share this post


Link to post

DisposeOf is only ever needed on ARC compiler. There using Free or DisposeOf are different things. On classic non-ARC compiler DisposeOf translates to Free, so it does not matter which one you use, it will behave the same.

 

Access violations mean that you are accessing object instance that is already released.

 

There are two likely scenarios: 

1. you are calling Free somewhere on object you are still using. On ARC compiler such instance would be kept alive (because Free just nils the reference and does not destroy the object if you have another strong reference(s))

2. you are calling DisposeOf on object you are still using, which on ARC compiler does not fully destroys the object (just calls destructor) but the object instance memory is accessible and intact so you can call methods on it (as long as you have some strong reference to that instance), or access fields without causing AV, unless you access something that has been explicitly destroyed in destructor.

 

Random behavior complicates things... such errors can be caused by threading issues.

Edited by Dalija Prasnikar

Share this post


Link to post

@David Heffernanyes, I do use that method, at least try too!

and yes I had deduced that I will be calling free on an object that that has already been freed or similar

so ARC has actually meant some underlying problem in my code I am getting away with it would seem?

 

thanks for the replies, I am more clearer now 🙂

Share this post


Link to post

I do see one thing I have done wrong in my linux code and that is I have

used

try

obj := TMyObject.Create;

 

  obj.DoSomething;

finally

  obj.Free;

end;

 

instead of

obj := TMyObject.Create;

try

  obj.DoSomething;

finally

  obj.Free;

end;

 

which could lead to the object being freed when its still in use?

Share this post


Link to post
38 minutes ago, mewindy said:

I do see one thing I have done wrong in my linux code and that is I have

used

try

obj := TMyObject.Create;

 

  obj.DoSomething;

finally

  obj.Free;

end;

 

instead of

obj := TMyObject.Create;

try

  obj.DoSomething;

finally

  obj.Free;

end;

 

which could lead to the object being freed when its still in use?

No. It could not lead to freeing object that is still in use.

 

But there is another thing that can happen here. Under ARC compiler all object references (variables) including local ones are initialized to nil before they are used and you can safely call Free on nil object.

 

In first example, if TMyObject constructor fails and raises an exception obj.Free will be called on uninitialized reference. If that uninitialized reference is nil by any chance, you will get lucky, if not you will trigger AV. 

 

But that does not fully explains random AVs, unless it happens after your "expected" exception from constructor.

Share this post


Link to post

a bit more info

If I run the linux program in the compiler its actually an eaccess violation

so I have some variable going out of range

or similar

the problem is I cant get the compiler to show the source code point as it wants to know the location of a .so linux library file..but that is only my linux machine

 

so I press ignore..the next time the error occurs I try trace into..but I just get the cpu screen...how do I use that info? 🙂

Share this post


Link to post

update, using try, except,then log the error,  i have managed to trap where the error is 

not sure what is wrong yet with the code but will try different things 

Share this post


Link to post

Can't you debug the code on windows. Might be easier there and now possible because the memory model is the same. 

 

On Linux you can of course use valgrind. 

Share this post


Link to post

OK, this is the problem code (illustration, i.e simplified) in 10.3

but not in 10.2

var

forimage:tbitmap;

begin

formimage:=layout1.makescreenshot;

end;

 

Edited by mewindy

Share this post


Link to post

OK..progress

it turns out

that I had a tchart on the layout1

and I had set thcart.enabled to false and also locked when doing the layout1.makescreenshot

setting those to false before the makescreenshot seems to have fixed it...

will test more..

so an obscure bug/change from 10.2 to 10.3 that has been driving me nuts lol

Share this post


Link to post

that was not it....the problem is the error is random..does not happen every time

Share this post


Link to post

i think its a red herring

as its random

I did see a message in the console about memory corruption

so something else going wrong someone else in my code but it just happens to be tripping up at that point?

Share this post


Link to post

I might have found the problem

a global variable that was initialised at form create needing to be re initialised when used  in a for loop (it must have been going out of range of the loop)

will know after more testing if that was it ...and nope after testing more..one day I might figure it out!

Edited by mewindy

Share this post


Link to post

We are doing just that. These continued postings are just noise for us. Clearly you have a problem but unless you can provide a clear reproducible case then your latest piece of guesswork doesn't warrant an update here. 

 

These bugs can be hard to track down. That's why we use tools like valgrind. They track them down instantly. 

  • Like 1

Share this post


Link to post

OK. for some reason

having a tchart

on the tlayout

is the problem when using tlayout.makescreenshot

 

if I set the tchart to not visible then no error

 

Share this post


Link to post

Dude, you've got a memory corruption somewhere, and the behaviour of such bugs is often not repeatable. Change something in one place, and the bug is hidden, only to pop up somewhere else.

 

I suggest that you stop posting here unless you have something concrete to share, and ask for help. Why are you posting you trial and error debugging in a public forum?

 

Do you know what valgrind is?

Share this post


Link to post

goodbye to this forum where you have people like this on here posting like this

 

Share this post


Link to post

We can help you but we need you to provide clear information. If you want to continue posting random scraps of information that mean nothing to us (we don't have your code, or a minimal reproduction), the posts in this thread are not actionable.

 

As somebody who has experience debugging memory I can assure you that you are going about it the wrong way. We can for sure help, but it requires you to provide clear information and take a more structured approach. If you don't want to do that, and wish to continue with trial and error, that's fine. But please don't consume bandwidth here by posting scraps of information that means nothing to us. 

 

Remember that this is a public forum. Every post you make is broadcast. We don't to spend our time sifting through posts looking for the useful actionable content.

Share this post


Link to post

Well, to the original posters favor.  This is, as you mentioned, a public forum.  It is not a payed support line.  If he wants to describe his problem and troubleshooting process you are in complete freedom to ignore it if it is irrelevant to you.  If you are glued to this forum, have notifications for every post and keep track of its hourly activity that is your doing.  "Consume bandwith?" "that means nothing to us?" who is us? is there some payed or volunteered group that has the obligation of responding to posts on this forum? if that is the case then I apologize and it is good to know, otherwise just move on and let the poster go crazy if he wants to.

Share this post


Link to post

@Esteban Pacheco TBH Both of them are nerving in some degree but in this case DH has a point, this was like an IRC like self-conversation leading to nowhere.

Edited by Attila Kovacs
  • Like 1

Share this post


Link to post
23 hours ago, mewindy said:

goodbye to this forum where you have people like this on here posting like this

 

Sad to see you leave. Please reconsider.

That said - should you stay, try seeing things from Davids POV. He is trying to help but that is kind of hard when he has to pull every tidbit of information out of you. David could have just stopped replying, which would have left you slightly more annoyed, I bet.

 

  • Like 2

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×