Puch Jerome
Puch Jerome

Reputation: 11

Application freezing android every 2sec

I have an application which capture frame(UDP) every 50ms and update my view with this data. But my application is freezing during 100/200ms every 2sec. In the LogCat a message appear : GC_CONCURRENT.

I don't know if a link exist between this message and my freezing. If yes, is there a solution to avoid this?`

            try {
                view.setClientSocket(new MulticastSocket(54321));
                ip = InetAddress.getByName("224.2.2.4");
                view.getClientSocket().joinGroup(ip);

            } catch (SocketException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            int cpt = 0;
            while(true){
                cpt++;
            try {
                if (view.isPort_change() == true){
                    view.setClientSocket(new MulticastSocket(54321));
                    ip = InetAddress.getByName("224.2.2.4");
                    view.getClientSocket().joinGroup(ip);
                    view.setPort_change(false);
            }

            int result = -1;            
            if(view.isCapture() == true && listeinit==true)
            {
                DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length,ip,54321);    
                view.getClientSocket().receive(receivePacket); 
                String modifiedSentence = new String(receivePacket.getData(),0,receivePacket.getLength());

                for(int i=0; i<modifiedSentence.split("\\+").length; i++)
                {
                    String[] donnee = modifiedSentence.split("\\+")[i].split(":");
                    for(Hashtable.Entry<Integer, String> entry : view.getAll_parameters().entrySet()){
                        if(entry.getValue().equals(donnee[0])){
                            result = entry.getKey();
                            break;
                        }
                    }
                    if (result== -1)
                    {
                        view.getBloc().add(donnee[1]);
                    }
                    else
                    {
                        view.getBloc().set(result,donnee[1]);                           
                    }
                }
             //     if(cpt%5==0)
                    {

                        view.getHandler().sendEmptyMessage(1);
                    }
            }
        }`

Upvotes: 1

Views: 111

Answers (1)

Samuel
Samuel

Reputation: 17171

GC_CONCURRENT means that a garbage collection is occurring. You are allocating/deallocating a lot of memory, and the JVM has to garbage collect every 2 sec. You should try to reuse memory instead of allocating and losing the reference to it every time you send a packet.

Upvotes: 1

Related Questions