On Aug 4, 2011, at 4:29 PM, Tim Kelly wrote:
> However, on another note.  One of the things I took out of the proof was a 
> HttpWebRequest and HttpWebResponse which hit the server.  So, I'm adding more 
> logging and have found one thing. 
>  
> Repeatedly calling these cause the network to stop functioning until you 
> reboot the emulator.  Calling the equivalent in java posses no issues.

I'm reminded of https://bugzilla.novell.com/show_bug.cgi?id=648862#c9

However, I see that you are disposing of `response` and other Stream instances, 
so I'm not sure where the leak is coming from. That said, you have lots of 
catch{} blocks; are those being hit? I ask because there are code paths where, 
if an exception were thrown, the stream wouldn't be closed:

                    Stream dataStream = request.GetRequestStream();
                    // Write the data to the request stream.
                    dataStream.Write(byteArray, 0, byteArray.Length);
                    // Close the Stream object.
                    dataStream.Close();

Instead, try:

        using (Stream dataStream = request.GetRequestStream())
                dataStream.WRite (byteArray, 0, byteArray.Length);

I would actually suggest using `using` more often, as I found that method hard 
to read (but that may be just me), e.g. a simple translation would be:

        private string GetData(string url, Boolean postData, String xmlData)
        {
                StringBuilder sb = new StringBuilder();
                try {
                        using (var request = (HttpWebRequest) 
WebRequest.Create(url)) {
                                request.ContentType = "text/plain";
                                if (postData) {
                                        request.Method = "POST";
                                        byte[] data = 
Encoding.ASCII.GetBytes(xmlData);
                                        request.ContentLength = data.Length;
                                        using (o = request.GetRequestStream())
                                                o.Write (data, 0, data.Length);
                                }
                                using (var response = (HttpWebResponse) 
request.GetReponse())
                                using (var resStream = 
response.GetResponseStream ()) {
                                        byte[] buf = new byte[4 * 1024];

                                        int count = 0;
                                        do {
                                                count = resStream.Read (buf, 0, 
buf.Length);
                                                if (count != 0)
                                                        sb.Append 
(Encoding.ASCII.GetString(buf, 0, count));
                                        } while (count > 0);
                                }
                        }
                } catch {}
                return sb.ToString ();
        }

 - Jon

_______________________________________________
Monodroid mailing list
[email protected]

UNSUBSCRIBE INFORMATION:
http://lists.ximian.com/mailman/listinfo/monodroid

Reply via email to