74695

NSURLConnection sendSynchronousRequest - is it possible to implement without leak

Question:

Is there a way to implement NSURLConnection without it leaking? A number of Apps including NYTimes and others (including mine) suffer from this. Anyone have a working implementation?

Answer1:

It appears that best practice is to use NSURLConnection asynchronously.

Answer2:

<a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nsurlconnection_Class/Reference/Reference.html#//apple_ref/occ/clm/NSURLConnection/sendSynchronousRequest:returningResponse:error:" rel="nofollow">According to the documentation</a>, +[NSURLConnection sendSynchronousRequest:returningResponse:error:] is built on top of the asynchronous loading code made available by NSURLConnection. It would not be difficult to reimplement this by spawning and blocking on an NSThread, running the request asynchronously in the background on a run loop and ending the thread once either connectionDidFinishLoading: or connection:didFailWithError: is received.

<sub>Of course, you are better off using the asynchronous code in the first place; it makes for a much better user experience</sub>

Recommend

  • How do I make a write operation in Realm (iOS) synchronous?
  • How atomic are mongoengine's operations
  • Start another EXE in Managed Code
  • Git and client/server code separation
  • python regex split string while keeping delimiter with value
  • How to distribute an event to all nodes in a (Wildfly) cluster?
  • Allocating a 2D contiguous array within a function
  • Oracle ListaGG, Top 3 most frequent values, given in one column, grouped by ID
  • Refactoring advice: maps to POJOs
  • php show all images in directory and sort by last modified
  • Copying rows in a database when rows have children
  • Receive list of elements in their visual order
  • Can't compile Arduino CapSense example
  • Want to understand iframe breakout code
  • Selectively hide background elements when overlayed with transparent div
  • Get the pasted content on document on paste event
  • Enumerating Controls on a Form
  • PayPal API Listener Website Payments Standard URI
  • MeeGo Handset Emulator not starting on Windows 7
  • In loopback documentation what does variable 'cb' stands for?
  • Why isn't obj.style.left = “200px”; working in this code?
  • Bootstrap (v3.3.4) glyphicons not displayed in IE when refresh page (F5)
  • How to autopopulate a field in SugarCRM form
  • Differences in dis-assembled C code of GCC and Borland?
  • Assign variable to the value in HTML
  • Installed module is empty
  • how to display data from 1st point on words on y axis for line chart in d3.js
  • Read a local file using javascript
  • Change multiple background-images with jQuery
  • Algorithm for a smudge tool?
  • Get one-time binding to work for ng-if
  • Retrieving value from sql ExecuteScalar()
  • Is there any way to access browser form field suggestions from JavaScript?
  • Can Jackson SerializationFeature be overridden per field or class?
  • Finding past revisions of files in StarTeam w/ .NET SDK / C#
  • Java applet as stand-alone Windows application?
  • Jquery - Jquery Wysiwyg return html as a string
  • Android Studio and gradle
  • SQL merge duplicate rows and join values that are different
  • Reading document lines to the user (python)