- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个 CryptoStream
和一个底层 Stream
。我不能使用 using
block 来处理 CryptoStream
,因为这也会处理我需要保持打开状态的底层 Stream
。解决方案似乎只是忽略 CryptoStream
并在需要时处理 Stream
。但也许保留对 CryptoStream
的引用并处理它以防止某些资源泄漏很重要?
此外,即使我不处置 CryptoStream
,如果它超出范围,GC 也可能处置它,然后还处置底层的 Stream
,(会不会太早了,因为我还需要 Stream
)?
最佳答案
protected override void Dispose(bool disposing) {
try {
if (disposing) {
if (!_finalBlockTransformed) {
FlushFinalBlock();
}
_stream.Close();
}
}
finally {
try {
// Ensure we don't try to transform the final block again if we get disposed twice
// since it's null after this
_finalBlockTransformed = true;
// we need to clear all the internal buffers
if (_InputBuffer != null)
Array.Clear(_InputBuffer, 0, _InputBuffer.Length);
if (_OutputBuffer != null)
Array.Clear(_OutputBuffer, 0, _OutputBuffer.Length);
_InputBuffer = null;
_OutputBuffer = null;
_canRead = false;
_canWrite = false;
}
finally {
base.Dispose(disposing);
}
}
}
如您所见,如果您不想释放 CryptoStream
,您应该调用公共(public)的 FlushFinalBlock
方法。此方法会清除输入和输出缓冲区,因此不会在使用的 CryptoStream
中存储任何敏感信息。
GC 是否会关闭底层的 Stream
?没有。为此,必须使用 true
作为参数值调用 Dispose
方法,但这仅在 Stream.Close
方法(称为来自 Stream.Dispose
)。即使 CryptoStream
将实现终结器,在执行 Finalize
时调用引用对象的 Dispose
也不是一个好习惯。终结器应该只用于释放非托管资源。
关于c# - 处理 CryptoStream 还是处理底层 Stream?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45401733/
我有以下功能: function addChange(result, bill) { for (var i=0;i
这是网站: www.wearethefirehouse.com/phasetest 如果您慢慢滚动,您会注意到一旦菜单栏完全不透明,nav li 元素就会全部从 Enzo 300 跳起来(如在没有导航
美好的一天。对于当前的项目,我需要知道数据类型如何表示为字节。例如,如果我使用: long three = 500;var bytes = BitConverter.GetBytes(three);
请解释 JVM 是如何在底层收集 ThreadDump 的。 我不明白它如何收集脱离 CPU 的线程的堆栈跟踪(等待磁盘 IO、网络、非自愿上下文切换)。 例如,linux perf 仅收集有关 on
开始学习 R,如果能帮助我理解 R 如何决定不同向量的类别,我将不胜感激。我初始化 vec <- c(1:6)当我执行 class(vec)我得到“整数”。为什么它不是“数字”,因为我认为 R 中的整
我有一个透明的 UIView,几乎覆盖了整个屏幕。我在顶部留下了 50 像素。它是 View Controller View 的 subview 。 在UIView下面有一个继承自UIView的MyV
我很好奇对象是如何在 Nodejs 中显示的,在本例中是 Promise。使用 console.log(promiseObject) 时,输出的类型为 {状态:待处理} 这对我来说似乎很奇怪,因为在该
当您在 Windows Azure 中使用表服务 API 时,幕后到底在做什么?我想我在某处读到这没有使用 SQL Server。它是否执行哈希表,然后过滤器真的像映射/减少操作一样运行?我对这些东西
如何查看函数 concat 中的代码?它是如何做的?有没有人有代码的副本或在浏览器控制台中查看它的方法? console.dir 不给我访问权限 console.dir(Array.prototype
我是 C++ 的新手,所以如果这个问题的答案显而易见,我深表歉意。 我一直在编写 STL 样式的自定义数据结构,以此来提高我的技能。 (我实际上也确实需要这种结构,但出于学习目的,我有点过分了。) 此
我正在尝试使用 log4j appender 将日志发送到 GrayLog2 (log4j2-gelf)。所以我将我的依赖项添加到我的 pom.xml 配置 log4j2.xml 来配置我的 appe
我正在使用带有 vector 的 priority_queue 作为底层容器。但是我希望堆的大小非常大。我知道动态 vector 容量调整大小的问题。所以我正在寻找方法来为我的priority_que
我有一个 SqlDataAdapter,它填充了 21 行数据(4 列)。驱动它的 sproc 在几秒钟内在 SQL Mgmt Studio 中返回,但 .Fill() 需要 5 分钟。 Ar
我想实现一个屏幕控制按钮,按下它可以作为 GUI 交互的修饰符。 这对于 MouseArea 是不可能的,因为该 API 只能处理一个鼠标区域中的一个触摸点。 该限制不适用于 MultiPointTo
我试图将图像和 div 层置于包含 div 的中心,但到目前为止我无法让它从列的左侧移动。我尝试了几种不同的方法,但就是无法让它移动。即使 margin auto 技巧也不起作用,我怀疑这是因为 bo
需要明确的是,我不是在询问 HDFS 中的权限设置,而是在 ext3 中或在 HDFS 运行于其上的各个数据节点机器上使用的任何文件系统中。 p> 我知道我们设置了 sudo chown hduser
我在服务器上创建了一个枚举,其中手动设置了整数值,而不是默认从 0 开始递增 public enum UserType { Anonymous = 0, Customer = 10,
如果显示框架图像,我们能否使以下 Google map 具有交互性。 Vie
我有一个顶部有自定义状态栏的布局 [在 Apple 的状态栏下方],然后是 UIScrollview 在中间部分从左到右分页,然后我有一个 UIView 底部有一些自定义按钮。一个简单的三 Pane
事情是这样的。我有一个 MVC 操作,在该操作上,我应用了自定义 ActionFilterAttribute 来使反序列化工作。现在,我想要做的是根据在此 View 中设置的 ViewBag.Titl
我是一名优秀的程序员,十分优秀!