找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 512|回复: 0

[他山之石] 外部COM进程不终止的处理方法

[复制链接]
发表于 2013-5-27 08:06:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
External COM processes do not terminate, if created with (vlax-get-or-create-object)

By Gopinath Taget

It is recommended that developers call (vlax-release-object...) on all external objects after they are done with them. However, it should be noted that calling (vlax-release-object...) does not always release the object at that exact time. The object is not actually released until all LISP symbols referencing the server's COM objects go out of scope or are set to nil AND a garbage-collection (gc) happens. The actual COM call to "release" happens only in a (gc) and only if LISP agrees that the object is no longer referenced.

You can force a garbage-collection with the lisp function (gc). Before you invoke Excel's Quit method, insert the call to (gc) into your code. This should allow (vlax-release-object ...) to remove Excel.exe from the process list. See below:
  1. (defun Test ()
  2.    (vl-load-com)
  3.    (setq XLAPP (vlax-get-or-create-object "Excel.Application"))
  4.    (vlax-dump-object XLAPP T)
  5.    (gc) ; release temporary com objects
  6.    (vlax-invoke-method XLAPP 'Quit)
  7.    (vlax-release-object XLAPP)
  8.    (setq XLAPP nil)
  9.    (gc)
  10. )
While this technique is generally supported, it should be noted that forcing too many (gc) calls (i.e. within loops that iterate hundreds of times), will have a negative impact on performance.
  NOTE: The VLIDE may be attached to many COM objects during a debug session. A COM server like Excel, will not be released until all of the internal VLIDE symbols referencing Excel objects go out of scope. The user/developer has no direct control over when the VLIDE internal symbols go out of scope. Closing the VLIDE does not make them go out of scope. The VLIDE never fully goes away once it has been started in a session. If developers are having trouble seeing the COM server released in a timely fashion, they should try running their application without ever having run the VLIDE in a session.

评分

参与人数 1D豆 +3 收起 理由
牢固 + 3 很给力!经验;技术要点;资料分享奖!

查看全部评分

论坛插件加载方法
发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;
如果你在论坛求助问题,并且已经从坛友或者管理的回复中解决了问题,请把帖子标题加上【已解决】;
如何回报帮助你解决问题的坛友,一个好办法就是给对方加【D豆】,加分不会扣除自己的积分,做一个热心并受欢迎的人!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|申请友链|Archiver|手机版|小黑屋|辽公网安备|晓东CAD家园 ( 辽ICP备15016793号 )

GMT+8, 2024-11-15 20:38 , Processed in 0.154569 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表