Nowadays, the powerful development of embedded software, the optimizing embedded software play an important role. The evaluation and optimization in the design phase of embedded software brings many benefits. In this paper, we propose a new method to optimize the occupied memory of embedded software in the design phase based on DSL, T4 and Topological sort. A program is a chain of Tasks and the relationship between each Task. The program is specified by the dependence graph that is a directed graph. Each node in directed graph describes a Task, each Task consists of specification information such as name, input, output. Each edge describes the relationship between two Tasks. The programs working by order of Task in the different Topo chain does not change the result but the occupied memory and performances are difference. From the dependence graph, we can find many Topo chains, and each of them will have amount of occupied memory in difference. From the Topo chains on the directed graph, we built the memory evaluation function to find the best Topo chain which has the smallest amount of occupied memory.