mewindy 0 Posted May 7, 2019 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
David Heffernan 2345 Posted May 7, 2019 Use classic memory management. obj := TMyObject.Create; try obj.DoSomething; finally obj.Free; end; Share this post Link to post
Dalija Prasnikar 1396 Posted May 7, 2019 (edited) 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 May 7, 2019 by Dalija Prasnikar Share this post Link to post
mewindy 0 Posted May 7, 2019 @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
mewindy 0 Posted May 7, 2019 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
Dalija Prasnikar 1396 Posted May 7, 2019 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
mewindy 0 Posted May 8, 2019 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
mewindy 0 Posted May 9, 2019 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
David Heffernan 2345 Posted May 9, 2019 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
mewindy 0 Posted May 9, 2019 (edited) 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 May 9, 2019 by mewindy Share this post Link to post
mewindy 0 Posted May 9, 2019 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
mewindy 0 Posted May 9, 2019 that was not it....the problem is the error is random..does not happen every time Share this post Link to post
mewindy 0 Posted May 10, 2019 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
mewindy 0 Posted May 10, 2019 (edited) 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 May 10, 2019 by mewindy Share this post Link to post
mewindy 0 Posted May 13, 2019 (edited) ignore Edited May 13, 2019 by mewindy Share this post Link to post
David Heffernan 2345 Posted May 13, 2019 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. 1 Share this post Link to post
mewindy 0 Posted May 13, 2019 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
David Heffernan 2345 Posted May 13, 2019 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
mewindy 0 Posted May 13, 2019 goodbye to this forum where you have people like this on here posting like this Share this post Link to post
David Heffernan 2345 Posted May 13, 2019 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
Esteban Pacheco 16 Posted May 13, 2019 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
Attila Kovacs 629 Posted May 13, 2019 (edited) @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 May 13, 2019 by Attila Kovacs 1 Share this post Link to post
Sherlock 663 Posted May 14, 2019 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. 2 Share this post Link to post