The use of mobile applications and their functionality are increasing day by day but mobile devices are still inferior to ordinary computers in terms of memory and processor capacity. Furthermore, the rapid depletion of the mobile devices' energy is still a major problem. Performance and energy shortcomings of mobile devices can be improved by using surrogate or cloud computing technologies. In particular, computation and memory intensive real time applications would be efficiently run by utilizing the resources of a remote server. In this paper, a novel offloading framework based on the Inversion of Control mechanism is developed to overcome the shortcomings and limitations of the current offloading approaches published in the literature. The proposed offloading framework reduces the burden on programmers. It implements application partitioning and code offloading via remote proxy classes and seamlessly provides callback functionality. In an application, it is possible to migrate different combinations of application components to remote servers. Some of these combinations can be productive and others can be counterproductive for offloading. In order to decide on components to be offloaded, a call graph model based on the collaboration of application's classes is developed. An offloading decision algorithm is presented to determine the classes to be offloaded by finding the best application partitioning in the graph. The framework and the graph model are evaluated by several experiments. Experimental results show that the proposed graph model fits well to the application partitioning problem. It has also been shown that offloading the optimal combination of components to remote servers can considerably reduce the execution time and energy consumption of mobile devices. (C) 2016 Elsevier Ltd. All rights reserved.