Using dfSplat to identify object leaks: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
m
mNo edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
=== Preface ===
=== Preface ===
One of the problems when developing a program which has a lot of dynamic objects is that you make sure that all the objects that are created are also destroyed after usage. If you don't remove them all after usage, you'll end up with memory leaks and those can be rather unpleasant as they cause problems that are hard to track down.
One of the problems when developing a program which has a lot of dynamic objects is, that you have to make sure that all the objects that have been created are also destroyed after usage. If you do not remove all of them after usage, then you end up with memory leaks. Memory leaks can be rather unpleasant as they cause problems which are hard to track down.


A couple of areas where you see a lot of usage with dynamic objects is when working with XML and JSON.
A couple of areas where you see a lot of usage with dynamic objects is when working with XML and JSON.
Line 35: Line 35:
</source>
</source>


As you can see we are creating 20 objects based on the cObject class and store the object ID's in Objects array.
As you can see we are creating 21 objects based on the cObject class and store the object ID's in Objects array.
Then there's some code we are not showing where the objects are used for whatever and finally we destroy the objects.
Then there's some code we are not showing where the objects are used for whatever and finally we destroy the objects.
But.. we only destroy objects with an even object ID, so we are leaking 10 objects on purpose here to display how it works.
But.. we only destroy objects with an even object ID, so we are leaking 10 objects here, on purpose in order to display how this technique works.


=== How to run the application in dfSplat ===
=== How to run the application in dfSplat ===
Line 88: Line 88:
[[File:dfSplat-LeakyObjects-Object-Inspector-Second-stop.png]]
[[File:dfSplat-LeakyObjects-Object-Inspector-Second-stop.png]]


As you can see now, our 20 test objects have been created.
As you can see now, our 21 test objects have been created.


So far, not all that exciting.
So far, not all that exciting.
Line 106: Line 106:
=== Final notes ===
=== Final notes ===


* Beware that you use the Object Inspector and not the Panel Inspector as the latter one is not suitable for this task. The Object Inspector will enumerate ALL objects in your application and test which are object actually exist or not. The Panel Inspector will only query the objects for the current panel and if objects are created dynamically it won't actually show them! The Panel Inspector was created to give you much faster access to your current view or panel, but it does that at the cost of not enumerating every object (hence why it is faster)
* Beware that you use the Object Inspector and not the Panel Inspector as the latter one is not suitable for this task. The Object Inspector will enumerate ALL objects in your application and tests which of those objects actually exist or not. The Panel Inspector will only query the objects for the current panel and if objects are created dynamically, it won't actually show them! The Panel Inspector was created to give you much faster access to your current view or panel, but it does that at the cost of not enumerating every object (hence why it is faster)


* If you want to test your code to see if it does correctly destroy all the dynamic objects it creates then it is most likely best to create a small temporary program for that. Obviously you can debug your full program, but the object inspector might be very slow to process every single object in your program on opening each time.
* If you want to test your code to see if it does correctly destroy all the dynamic objects it creates then it is most likely best to create a small temporary program for that. Obviously you can debug your full program, but the object inspector might be very slow to process every single object in your program on opening each time.

Navigation menu