Bob Swart wrote: > Hi CubicDesign, > >> Also: if I disable Compiler Optimization, the application works as >> expected (access violation). > > This should be a clue: the compiler sees the statement as useless, since > it isn't used anywhere else anyway, and removes the statement (when > Compiler Optimization is enabled)...
The compiler never sees a function call as useless. The compiler does not do interprocedural analysis, which is what is required to determine that a function call has no effect. Without that analysis, the compiler can never remove a function call. (*If* the method is "inline," then the compiler *might* determine after expanding the inline function that the function doesn't do anything, although I doubt the compiler is that sophisticated. But it won't reach that conclusion in this case since TObject.Free definitely does something. It checks the value of the receiver -- Self -- for nil. The compiler doesn't know what that value will be; the value is uninitialized in the caller, so it could be anything. The call to Free cannot be optimized out.) I suspect the optimization setting determines whether the compiler reserves space on the stack for the (uninitialized) variable or whether the variable lives purely in a register. -- Rob _______________________________________________ Delphi mailing list -> [email protected] http://lists.elists.org/cgi-bin/mailman/listinfo/delphi

