访问类型声明对释放的影响 [英] Access type declaration effect on deallocation

查看:52
本文介绍了访问类型声明对释放的影响的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这两种情况下,是否在声明块之后(以及过程结束之前)以相同的方式释放了内存:

Is the memory freed the same way after the declare block (and before the end of the procedure of course) in both cases:

procedure allocation is 
    type T_Integer_Access is access Integer;
begin
    declare
        P : T_Integer_Access;
    begin
        P := new Integer'(5);
    end;
end;

procedure allocation is 
begin
    declare
        type T_Integer_Access is access Integer;
        P : T_Integer_Access;
    begin
        P := new Integer'(5);
    end;
end;

换一种说法,访问类型声明对内存释放有影响吗?

Put another way, has the access type declaration an effect on memory deallocation?

推荐答案

很有可能存储池(内存区域)中的对象类型为 T_Integer_Access 因为您尚未定义自己的存储池,所以分配的分配将永远不会被释放; AARM 13.11 在(2.a )

There’s a good chance that the storage pool (memory arena) from which objects of type T_Integer_Access is allocated won’t be freed ever, since you haven’t defined your own storage pool; AARM 13.11 says at (2.a)


默认情况下,实现可能会选择使用一个全局存储池,默认情况下,所有访问类型都使用该存储池,这可能意味着仅在分区完成后才自动回收存储。或者,它可能选择在每个可访问性级别上创建一个新池,这可能意味着在离开适当的作用域时,将为访问类型回收存储。其他方案也是可能的。

By default, the implementation might choose to have a single global storage pool, which is used (by default) by all access types, which might mean that storage is reclaimed automatically only upon partition completion. Alternatively, it might choose to create a new pool at each accessibility level, which might mean that storage is reclaimed for an access type when leaving the appropriate scope. Other schemes are possible.

-换句话说,它不是语言指定的。

-- in other words, it’s not specified by the language.

我认为定义除库级别以外的对象访问类型是非常不寻常的。我从来没有做过,所以我不知道编译器实际上是做什么的。

I think it’s very unusual to define access-to-object types other than at library level. I’ve never done it, so I don’t know what compilers actually do.

更新:

valgrind 不能在macOS Sierra上运行,所以我尝试使用GNAT GPL 2016在Debian jessie上运行;您的分配绝对是泄漏内存。

valgrind doesn’t run on macOS Sierra, so I tried on Debian jessie with GNAT GPL 2016; both your Allocations definitely leak memory.

存储池是可终结的,因此您可以实现自己的存储池;或者您可以查看例如 Deepend

Storage pools are finalizable, so you could implement your own; or you might look at, for example, Deepend.

这篇关于访问类型声明对释放的影响的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆