I have also this problem On 22 Temmuz, 03:18, Bo <zhaobo...@gmail.com> wrote: > Dear Sir: > > I developed a FTP uploading program which upload the string to a text > file through FTP. This program only works well as an Java application > on PC, but when I put the same code to Android application on > Emulator, Android always begins to grow heap and allocate memory when > the code calls the function"URLConnection.getOutputStream()", and > finally Android is "Out of memory". I have suffered from this problem > for a week. If you could help me, I really appreciate! > > Below is the code and debug trace got by "adb logcat". (I replace the > host, user, password and targetfile with some common strings.) > > String host = "hostname"; > String user = "username"; > String password = "password"; > String targetfile = "filename"; > > try{ > URL url= new URL("ftp://"+ user+ ":"+ password+ > "@"+ host+ "/"+ targetfile + ";type=i"); > URLConnection urlc = url.openConnection(); > Log.d("DEBUG", " openconnection done"); > > OutputStream os = urlc.getOutputStream();// > problem happens from this line > Log.d("DEBUG","get OutputStream"); > String packet_str = "Uploading"; > byte[] buf = packet_str.getBytes(); > os.write(buf); > Log.d("DEBUG","write done"); > os.close(); > urlc= null; > }catch (Exception E) { > Log.d("DEBUG","Erro Happen!" + E.getMessage > ()); > E.printStackTrace(); > } > > Below is the trace: > > D/DEBUG ( 719): openconnection done > D/InetAddress( 719): xzzb.hostrator.com: 64.191.109.6 (family 2, > proto 6) > D/dalvikvm( 637): GC freed 2854 objects / 162328 bytes in 177ms > D/dalvikvm( 719): GC freed 14245 objects / 422552 bytes in 84ms > D/dalvikvm( 719): GC freed 19713 objects / 529824 bytes in 75ms > D/dalvikvm( 719): GC freed 17813 objects / 501656 bytes in 78ms > D/dalvikvm( 719): GC freed 23615 objects / 567184 bytes in 82ms > > ..... > > D/dalvikvm( 719): GC freed 74935 objects / 1798504 bytes in 162ms > D/dalvikvm( 719): GC freed 74935 objects / 1798504 bytes in 155ms > D/dalvikvm( 719): GC freed 43212 objects / 1037152 bytes in 118ms > I/dalvikvm-heap( 719): Forcing collection of SoftReferences for > 9437196-byte allocation > D/dalvikvm( 719): GC freed 0 objects / 0 bytes in 62ms > E/dalvikvm-heap( 719): Out of memory on a 9437196-byte allocation. > I/dalvikvm( 719): "main" prio=5 tid=3 RUNNABLE > I/dalvikvm( 719): | group="main" sCount=0 dsCount=0 s=0 > obj=0x40018e70 > I/dalvikvm( 719): | sysTid=719 nice=0 sched=0/0 handle=-1097544548 > I/dalvikvm( 719): at java.lang.AbstractStringBuilder.enlargeBuffer > (AbstractStringBuilder.java:~99) > I/dalvikvm( 719): at java.lang.AbstractStringBuilder.append0 > (AbstractStringBuilder.java:153) > I/dalvikvm( 719): at java.lang.StringBuffer.append > (StringBuffer.java:128) > I/dalvikvm( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.readLine > (FtpURLConnection.java:403) > I/dalvikvm( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.getReply > (FtpURLConnection.java:355) > I/dalvikvm( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.port > (FtpURLConnection.java:391) > I/dalvikvm( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.connectInternal > (FtpURLConnection.java:232) > I/dalvikvm( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.connect > (FtpURLConnection.java:189) > I/dalvikvm( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.getOutputStream > (FtpURLConnection.java:342) > I/dalvikvm( 719): at com.example.sendonce.sendonce$1.onClick > (sendonce.java:118) > I/dalvikvm( 719): at android.view.View.performClick(View.java:2179) > I/dalvikvm( 719): at android.view.View.onTouchEvent(View.java:3828) > I/dalvikvm( 719): at android.widget.TextView.onTouchEvent > (TextView.java:6291) > I/dalvikvm( 719): at android.view.View.dispatchTouchEvent > (View.java: > 3368) > I/dalvikvm( 719): at android.view.ViewGroup.dispatchTouchEvent > (ViewGroup.java:863) > I/dalvikvm( 719): at android.view.ViewGroup.dispatchTouchEvent > (ViewGroup.java:863) > I/dalvikvm( 719): at android.view.ViewGroup.dispatchTouchEvent > (ViewGroup.java:863) > I/dalvikvm( 719): at android.view.ViewGroup.dispatchTouchEvent > (ViewGroup.java:863) > I/dalvikvm( 719): at com.android.internal.policy.impl.PhoneWindow > $DecorView.superDispatchTouchEvent(PhoneWindow.java:1707) > I/dalvikvm( 719): at > com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent > (PhoneWindow.java:1197) > I/dalvikvm( 719): at android.app.Activity.dispatchTouchEvent > (Activity.java:1993) > I/dalvikvm( 719): at com.android.internal.policy.impl.PhoneWindow > $DecorView.dispatchTouchEvent(PhoneWindow.java:1691) > I/dalvikvm( 719): at android.view.ViewRoot.handleMessage > (ViewRoot.java:1525) > I/dalvikvm( 719): at android.os.Handler.dispatchMessage > (Handler.java:99) > I/dalvikvm( 719): at android.os.Looper.loop(Looper.java:123) > I/dalvikvm( 719): at android.app.ActivityThread.main > (ActivityThread.java:3948) > I/dalvikvm( 719): at java.lang.reflect.Method.invokeNative(Native > Method) > I/dalvikvm( 719): at java.lang.reflect.Method.invoke(Method.java: > 521) > I/dalvikvm( 719): at com.android.internal.os.ZygoteInit > $MethodAndArgsCaller.run(ZygoteInit.java:782) > I/dalvikvm( 719): at com.android.internal.os.ZygoteInit.main > (ZygoteInit.java:540) > I/dalvikvm( 719): at dalvik.system.NativeStart.main(Native Method) > I/dalvikvm( 719): > D/AndroidRuntime( 719): Shutting down VM > W/dalvikvm( 719): threadid=3: thread exiting with uncaught exception > (group=0x4000fe70) > E/AndroidRuntime( 719): Uncaught handler: thread main exiting due to > uncaught exception > E/AndroidRuntime( 719): java.lang.OutOfMemoryError > E/AndroidRuntime( 719): at > java.lang.AbstractStringBuilder.enlargeBuffer > (AbstractStringBuilder.java:99) > E/AndroidRuntime( 719): at > java.lang.AbstractStringBuilder.append0 > (AbstractStringBuilder.java:153) > E/AndroidRuntime( 719): at java.lang.StringBuffer.append > (StringBuffer.java:128) > E/AndroidRuntime( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.readLine > (FtpURLConnection.java:403) > E/AndroidRuntime( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.getReply > (FtpURLConnection.java:355) > E/AndroidRuntime( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.port > (FtpURLConnection.java:391) > E/AndroidRuntime( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.connectInternal > (FtpURLConnection.java:232) > E/AndroidRuntime( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.connect > (FtpURLConnection.java:189) > E/AndroidRuntime( 719): at > org.apache.harmony.luni.internal.net.www.protocol.ftp.FtpURLConnection.getOutputStream > (FtpURLConnection.java:342) > E/AndroidRuntime( 719): at com.example.sendonce.sendonce > $1.onClick > (sendonce.java:118) > E/AndroidRuntime( 719): at android.view.View.performClick > (View.java:2179) > E/AndroidRuntime( 719): at android.view.View.onTouchEvent > (View.java:3828) > E/AndroidRuntime( 719): at android.widget.TextView.onTouchEvent > (TextView.java:6291) > E/AndroidRuntime( 719): at android.view.View.dispatchTouchEvent > (View.java:3368) > E/AndroidRuntime( 719): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) > E/AndroidRuntime( 719): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) > E/AndroidRuntime( 719): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) > E/AndroidRuntime( 719): at > android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:863) > E/AndroidRuntime( 719): at > com.android.internal.policy.impl.PhoneWindow > $DecorView.superDispatchTouchEvent(PhoneWindow.java:1707) > E/AndroidRuntime( 719): at > com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent > (PhoneWindow.java:1197) > E/AndroidRuntime( 719): at > android.app.Activity.dispatchTouchEvent > (Activity.java:1993) > E/AndroidRuntime( 719): at > com.android.internal.policy.impl.PhoneWindow > $DecorView.dispatchTouchEvent(PhoneWindow.java:1691) > E/AndroidRuntime( 719): at android.view.ViewRoot.handleMessage > (ViewRoot.java:1525) > E/AndroidRuntime( 719): at android.os.Handler.dispatchMessage > (Handler.java:99) > E/AndroidRuntime( 719): at android.os.Looper.loop(Looper.java: > 123) > E/AndroidRuntime( 719): at android.app.ActivityThread.main > (ActivityThread.java:3948) > E/AndroidRuntime( 719): at java.lang.reflect.Method.invokeNative > (Native Method) > E/AndroidRuntime( 719): at java.lang.reflect.Method.invoke > (Method.java:521) > E/AndroidRuntime( 719): at com.android.internal.os.ZygoteInit > $MethodAndArgsCaller.run(ZygoteInit.java:782) > E/AndroidRuntime( 719): at > com.android.internal.os.ZygoteInit.main > (ZygoteInit.java:540) > E/AndroidRuntime( 719): at dalvik.system.NativeStart.main(Native > Method) > I/Process ( 569): Sending signal. PID: 719 SIG: 3 > I/dalvikvm( 719): threadid=7: reacting to signal 3 > I/dalvikvm( 719): Wrote stack trace to '/data/anr/traces.txt' > > Thank you! > Bo
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---