Closed gaearon closed 10 years ago
This seems to happen when large NSData
is passed to FoundationResponse
constructor.
In my case, its length was 498430
.
I'll see why the data is so large, but still the crash is weird, is the memory being freed too soon?
I'll see why the data is so large, but still the crash is weird, is the memory being freed too soon?
Looks like a possibility, I don't see anything holding on to a reference of the NSData.
Would it be better to hold on to NSData
or to pin it and store GCHandle
? I suppose without pinning, its address could change, no? Or does it not matter because its Bytes
point to native memory GC can't move anyway? Thanks.
Probably simpler to just hold on to the NSData
, as you said the Bytes
is going to be unmanaged memory. Really the construction of the new stream could be moved to GetResponseStream
if we hold on to the NSData
as well.
I see. Should I dispose of both stream
and NSData
in Dispose
, or just NSData
? Do I need to put Dispose
calls inside if (disposing)
?
Do I need to put Dispose calls inside if (disposing)?
Yes, NSObject
has its own finalizer and the execution order of finalizers is not guaranteed.
The real question is why @praeclarum special cases NSMutableData
? AsStream()
automatically keeps a reference to the NSData
.
@ermau
But FoundationResponse
's base class is Response
, not NSObject
. It just follows the same convention.
It also frees its own field (HttpWebResponse response
) without doing this check.
But FoundationResponse's base class is Response, not NSObject.
NSData
's base class is NSObject
.
It also frees its own field (HttpWebResponse response) without doing this check.
True, that doesn't make it correct unfortunately. I'll have to fix that.
I can't isolate the issue yet, but I have
FoundationResponse.GetResponseText()
crashing my process in some cases: