程序退出后,win95 会清除资源吗(100分)

  • 主题发起人 主题发起人 leewheel
  • 开始时间 开始时间
L

leewheel

Unregistered / Unconfirmed
GUEST, unregistred user!
我从资料看到32位windows能跟踪程序资源,在程序退出时会将handle,
GDI资源如hbitmap,hdc等自动删除。我想知道自己创建的全局类实例如
TBitmap等和分配的内存用不用free(Delete),程序结束是否自动析构。
另外,我浏览大富翁看到如下:程序运行时动态创建的组件如TEdit必
须在退出时编程free。对此我不理解,vcl中容器组件Free时会通知其拥
有组件,拥有的组件会响应消息删除自己,不知是否我理解有误。
 
Use Free to destroy an object. Free automatically calls the Destroy if the object instance is not nil. Any object instantiated at runtime thatdo
es not have an Owner should be destroyed by a call to Free, so that the object can be properly destroyed and the memory released. Free is successful even if the object is nil, so if the object was never initialized, for example, calling Free won抰 result in an error.
When you call Free for a component, it will call Free for all components that it owns, that is, all components in its component list. A form owns all the controls and non-visual components that are created on it in design mode. When it is freed, all of these components are automatically freed as well. Since, by default, all forms are owned by the Application object, when the application terminates, it frees the Application object, which frees all forms. For all objects that are not components, or for components created by a nil owner, be sure to call Free after you are finished with the object;
otherwise the memory allocated to the object will not be usable until after the application terminates.
You should never explicitly free a component within one of its own event handlers, nor should you free a component from an event handler of a component the component owns or contains. For example, you should avoid freeing a button in its OnClick event handler. Nor should you free the form that owns the button from the button's OnClick event.
If you want to free the form, call the Release method, which destroys the form and releases the memory allocated for it after all its event handlers and those of the components it contains are through executing.
 
你必须自己释放资源。
 
Use Free to destroy an object. Free automatically calls the Destroy
if the object instance is not nil. Any object instantiated at runtime
thatdo
es not have an Owner should be destroyed by a call to Free, so
that the object can be properly destroyed and the memory released.
Free is successful even if the object is nil, so if the object was
never initialized, for example, calling Free won抰 result in an error.
When you call Free for a component, it will call Free for all
components that it owns, that is, all components in its component
list. A form owns all the controls and non-visual components that are
created on it in design mode. When it is freed, all of these
components are automatically freed as well. Since, by default, all
forms are owned by the Application object, when the application
terminates, it frees the Application object, which frees all forms.
For all objects that are not components, or for components created by
a nil owner, be sure to call Free after you are finished with the
object;
otherwise the memory allocated to the object will not be
usable until after the application terminates.

You should never explicitly free a component within one of its own event handlers, nor should you free a component from an event handler of a component the component owns or contains. For example, you should avoid freeing a button in its OnClick event handler. Nor should you free the form that owns the button from the button's OnClick event.
If you want to free the form, call the Release method, which destroys the form and releases the memory allocated for it after all its event handlers and those of the components it contains are through executing.
 
怎么看都象是Delphi 的帮助上Copy 下来的。
 
没错,
别冲我仍鸡蛋!
帮助文件不是说的很清楚了吗.
 
windows不会自己释放你程序中申请的资源. 不信可以做个很简单的测试. 打开资源监视器.
var
bmp: TBitmap;
procedure TForm1.Button1Click(Sender: TObject);
begin
bmp := TBitmap.Create;
bmp.width := 500;
bmp.height := 500;
....
end;
不用几次你就会得到资源耗尽的提示. 退出程序也没用.
会自动free的只有继承自TComponent的类对象, 并且生成时指定了owner.
 
不错,
动态创建的对象必须释放资源。
 
一般来说所有用new生成的对象都要用free/delete删除,但其中有一种情况是vcl会负责释放为mdi子窗口分配的内存.mdi窗体删除时,会自动删除其所有mdi子对象.
其他我同意Another_eYes
 
具我所知,多数以APPLICATION或其儿子女儿们为OWNER的资源会自动释放,
而没有 OWNER 的不能释放。分是我的,大家别抢:)
 
程序运行时分配资源必须在退出时释放。
这是一名合格程序员的责任!!!!!!
 
那么在TREEVIEW/LISTVIEW中为某个ITEM申请DATA字串,在
1、CLEAR时
2、程序退出时
会不会自动释放呢?
 
bitmap
dll
variant
都占用资源,需要你自己释放
 
程序结束时大概会, 没试过, 一般这种编译器都有无用内存回收程序的. 申请的内存块(在本进程中)
在进程结束时会释放.
 
多人接受答案了。
 
后退
顶部