On 11/11/16 10:25, Ryan Joseph wrote:
On Nov 11, 2016, at 4:56 PM, Tony Whyman <tony.why...@mccallumwhyman.com> wrote:

3. To get an object back from an interface you must use the "as" operator.
Another point to do with CORBA. The manual says they are not reference counted 
and programmer needs to do book keeping. The crash I was getting was in line 
with accessing memory that has been deallocated so perhaps because I didn’t do 
my “book keeping” it was freed as it passed scopes. Not sure how to manage 
reference counting for interfaces though because the docs didn’t actually 
explain this.

Maybe the better question is should I ditch CORBA in favor or COM?


Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

If last question doesn't send the list into overdrive then nothing will;)

With CORBA you are responsible for freeing the objects that provide an interface in the same way that you are always responsible for freeing the objects that you create. If you free an object before you finish using it then it's a bug and using interfaces does not change that.

With COM, once you assign the object providing the interface to a variable with an interface type then you are no longer responsible for freeing the object. The object is now managed by the system and if you do free it then you get an exception. It's really the same principle as AnsiStrings and dynamic arrays, which are also reference counted objects.

The classic newbie problem with COM comes when you have an interface with a method that returns another interface. If the underlying objects "know" about each other and reference each other's data then the order in which they are freed becomes important and automatic reference counting does not always give the right answer. There are design techniques to manage this, such as objects keeping interface references to other objects - but then you have to be careful to avoid circular references that prevent the objects ever being released.

I would start working with interfaces by using CORBA. It's more obvious what is going on and fewer traps for the unwary. However, if you are designing a standard package providing an API realised as a Pascal Interface then I would argue that a properly designed COM based interface is easier for the API user, in the same way that AnsiStrings just "work".
_______________________________________________
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Reply via email to