Program exception "attempts to read or write protected memory, which usually indicates that other memory is damaged"

Source: Internet
Author: User
"Trying to read or write protected memory usually indicates that other memory is corrupted ".

System. accessviolationexception: attempted to read or write protected memory.
This is often an indication that other memory is invalid upt.
This type of error is not uncommon, especially for image development and COM Component Operations. Do not expect this article to give you a clear answer, but only provide you with a solution:
There is only one solution: Eye View or exclusion. Let's take a look at the priority of exclusion:

1. If you use nativecode resources, such as COM and ActiveX;
There is no forcible release method. The underlying COM component controls the addition and release of Objects Based on the number of times your process calls the component (the object release will be delayed, and the com itself will be faulty ).
Generally, the method is called to force garbage collection or the method that AO comes with to recycle objects, and the effect is not obvious.
This kind of object is not released, usually occurs in the ApplicationProgramWhen the frequency of repeated calls is extremely high,The call interval is shorter than the object reclaim speed..
This is usually the case only when the organizations that write their own programs are unreasonable.
Forcibly release com Resources in the program. Call the Al. releasecomobject () method to release unused objects.
And catch where exceptions may occur, and leave logs to transfer this exception.

2. indicates that the test is executable.FileProtection against Windows DataFunctionCompatible.
Call the DLLProgramWhen running, "try to read or write the protected memory. This usually indicates that other memory is damaged. "
For more information, see/nxcompat (compatible with Data Execution Protection ).
The DEP security check is added to the compiler. Canceling the nxcompat bit in the compiled EXE file can solve this problem.
Editbin.exe/nxcompat: No myexe

3. exclude environmental factors: for example, the gap between. Net FX 2.0 and. Net FX 2.0 SP2 is very large. Of course, other environmental factors are also considered.
Be sure to eliminate problems caused by differences in development and deployment environments.

4. If this problem occurs suddenly, it is best to roll back to the previous operation and redo this operation, such as removing the control and adding it again;
Re-register com. If you have installed other plug-ins, uninstall these plug-ins and try again.

5. Program problems. For example, a deadlock occurs when database access reaches the maximum concurrency. Or frequent write and read operations, caused by the garbage collection mechanism of C #, that is, the variable recovery speed is higher than the usage speed, so that we need to design a newAlgorithm.

Attitude determines everything, technology changes life

Author: winzheng
Source: http://cnblogs.com/winzheng
This article is an original work. You are welcome to repost it, but you must keep this statement without the consent of the author. Article The original text link is clearly displayed on the page. Otherwise, the legal liability is retained.

 

More references http://msdn.microsoft.com/zh-cn/library/ms164911%28VS.80%29.aspx

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.