Life cycle of the "Talk Interface" interface object-block cleanup of memory occupied by the object

Source: Internet
Author: User

Overview

Believe that often use the interface of friends, often encounter access violation exception (access violation), in many cases can not understand, think of the compiler bug, and then go around it, do not chase its roots, the responsibility to the IDE, push to the compiler (in fact, I often think so). In fact, each anomaly is a reason, encounter this problem do not bypass, if at present can not solve, at least to know clearly the cause of its emergence, not let go of every traced the chance. This is the mindset that programmers should have. (It seems a bit far away ...)

"Problem description"

Today the Company outsourcing module, the outsourcing personnel response to a very strange problem, said the module in the absence of an AV anomaly. debugging is so, and every time can appear, every time the exception can be resolved,

The initial code is as follows:

A Click Button event contains the following code:

begin   ....  (Tmbeanframevars.getbean ('ef_pcy_frmtree' as inormalselector). ExecuteSelect (lvpass);  .... End;

In this way, the program throws an AV exception (end; after running) when exiting the function, which is usually not known to the interface. Can not start debugging.

"Problem Analysis"

First of all, this simple access will actually present the temporary variable of the interface, and this variable will be cleaned when the function exits, because the ExecuteSelect function frees the plug-in instance and then cleans up the temporary interface variable, which triggers the __release method of the interface object. An exception that is thrown at this time.

I modified the code so that the error occurs before the function exits, and the complete code is as follows.

I use two local variables, so after the transformation, the implementation of lvintf: = nil When the AV error occurs.

By the way, I executeselect the code to see that this plugin is a Form object instance. In executing this function, the form is displayed, then released, and the function is exited.

Probably the reason to understand after we adjust the code, the code is as follows:

Note the red part, after the selection (after releasing the instance), and then immediately clean up the interface variables, this time, the memory block should still be complete (personal speculation), so clean up without an access violation exception.

I'm going to do a commissioning to prove my theory.

Look at the red box out of the section, two interface variables after the release, and the previous point in the memory block the value is the same (I only get a value, can actually be a full comparison), and then continue to execute.

Looking at the Red section, this time (actually playing cdsorgan.append), lvintf points to the memory block has been cleaned up, because there is a new memory request. So there is an access violation error when cleaning lvintf: = nil.

Well, at this point, we should find the real reason for the exception: when the interface variable is cleaned, an unpredictable block of memory is accessed, resulting in an access violation error. So please pay attention to the clean-up work of the interface during the use of the interface.

* Read more and you will reap more.

==========================================

DIOCP Official Community | Mybean Official Community

http://www.diocp.org/

==========================================

The life cycle of the "Talk Interface" interface object-the memory block cleanup that the object occupies

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.