[Foundation] Ensure that we retain the needed data in the NSUrlSessionHandler (#3731)

* Do not release the NSData because buffers are reused between requests.
* Remove unneeded dipose override.
This commit is contained in:
Manuel de la Pena 2018-03-16 10:51:40 +01:00 коммит произвёл GitHub
Родитель 9c58c4513a
Коммит cf3648e33f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 8 добавлений и 11 удалений

Просмотреть файл

@ -462,16 +462,6 @@ namespace Foundation {
data = new Queue<NSData> ();
}
protected override void Dispose (bool disposing)
{
lock (dataLock) {
foreach (var q in data)
q?.Dispose ();
}
base.Dispose (disposing);
}
public void Add (NSData d)
{
lock (dataLock) {
@ -539,8 +529,15 @@ namespace Foundation {
lock (dataLock) {
// this is the same object, it was done to make the cleanup
data.Dequeue ();
current?.Dispose ();
currentStream?.Dispose ();
// We cannot use current?.Dispose. The reason is the following one:
// In the DidReceiveResponse, if iOS realizes that a buffer can be reused,
// because the data is the same, it will do so. Such a situation does happen
// between requests, that is, request A and request B will get the same NSData
// (buffer) in the delegate. In this case, we cannot dispose the NSData because
// it might be that a different request received it and it is present in
// its NSUrlSessionDataTaskStream stream. We can only trust the gc to do the job
// which is better than copying the data over.
current = null;
currentStream = null;
}